1asprintf(3)                Library Functions Manual                asprintf(3)
2
3
4

NAME

6       asprintf, vasprintf - print to allocated string
7

LIBRARY

9       Standard C library (libc, -lc)
10

SYNOPSIS

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

DESCRIPTION

20       The  functions asprintf() and vasprintf() are analogs of sprintf(3) and
21       vsprintf(3), except that they allocate a string large  enough  to  hold
22       the  output  including  the  terminating null byte ('\0'), and return a
23       pointer to it via the first argument.  This pointer should be passed to
24       free(3) to release the allocated storage when it is no longer needed.
25

RETURN VALUE

27       When  successful,  these  functions return the number of bytes printed,
28       just like sprintf(3).  If memory allocation wasn't  possible,  or  some
29       other error occurs, these functions will return -1, and the contents of
30       strp are undefined.
31

ATTRIBUTES

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

VERSIONS

43       The FreeBSD implementation sets strp to NULL on error.
44

STANDARDS

46       GNU, BSD.
47

SEE ALSO

49       free(3), malloc(3), printf(3)
50
51
52
53Linux man-pages 6.05              2023-07-20                       asprintf(3)
Impressum