1ASPRINTF(3) Linux Programmer's Manual ASPRINTF(3)
2
3
4
6 asprintf, vasprintf - print to allocated string
7
9 #define _GNU_SOURCE /* See feature_test_macros(7) */
10 #include <stdio.h>
11
12 int asprintf(char **strp, const char *fmt, ...);
13
14 int vasprintf(char **strp, const char *fmt, va_list ap);
15
17 The functions asprintf() and vasprintf() are analogs of sprintf(3) and
18 vsprintf(3), except that they allocate a string large enough to hold
19 the output including the terminating null byte ('\0'), and return a
20 pointer to it via the first argument. This pointer should be passed to
21 free(3) to release the allocated storage when it is no longer needed.
22
24 When successful, these functions return the number of bytes printed,
25 just like sprintf(3). If memory allocation wasn't possible, or some
26 other error occurs, these functions will return -1, and the contents of
27 strp is undefined.
28
30 These functions are GNU extensions, not in C or POSIX. They are also
31 available under *BSD. The FreeBSD implementation sets strp to NULL on
32 error.
33
35 free(3), malloc(3), printf(3)
36
38 This page is part of release 3.53 of the Linux man-pages project. A
39 description of the project, and information about reporting bugs, can
40 be found at http://www.kernel.org/doc/man-pages/.
41
42
43
44GNU 2013-06-21 ASPRINTF(3)