1ASPRINTF(3)                Linux Programmer's Manual               ASPRINTF(3)
2
3
4

NAME

6       asprintf, vasprintf - print to allocated string
7

SYNOPSIS

9       #define _GNU_SOURCE         /* See feature_test_macros(7) */
10       #include <stdio.h>
11
12       int asprintf(char **restrict strp, const char *restrict fmt, ...);
13       int vasprintf(char **restrict strp, const char *restrict fmt,
14                     va_list ap);
15

DESCRIPTION

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

RETURN VALUE

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 are undefined.
28

ATTRIBUTES

30       For an  explanation  of  the  terms  used  in  this  section,  see  at‐
31       tributes(7).
32
33       ┌─────────────────────────────────────┬───────────────┬────────────────┐
34Interface                            Attribute     Value          
35       ├─────────────────────────────────────┼───────────────┼────────────────┤
36asprintf(), vasprintf()              │ Thread safety │ MT-Safe locale │
37       └─────────────────────────────────────┴───────────────┴────────────────┘
38

CONFORMING TO

40       These  functions  are GNU extensions, not in C or POSIX.  They are also
41       available under *BSD.  The FreeBSD implementation sets strp to NULL  on
42       error.
43

SEE ALSO

45       free(3), malloc(3), printf(3)
46

COLOPHON

48       This  page  is  part of release 5.13 of the Linux man-pages project.  A
49       description of the project, information about reporting bugs,  and  the
50       latest     version     of     this    page,    can    be    found    at
51       https://www.kernel.org/doc/man-pages/.
52
53
54
55GNU                               2021-03-22                       ASPRINTF(3)
Impressum