1ASPRINTF(3) Linux Programmer's Manual ASPRINTF(3)
2
3
4
6 asprintf, vasprintf - print to allocated string
7
9 #define _GNU_SOURCE
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 analogues of sprintf() and
18 vsprintf(), except that they allocate a string large enough to hold the
19 output including the terminating null byte, and return a pointer to it
20 via the first parameter. This pointer should be passed to free(3) to
21 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), feature_test_macros(7)
36
37
38
39GNU 2001-12-18 ASPRINTF(3)