]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man3/asprintf.3
proc.5: Note kernel version for /proc/PID/smaps VmFlags "wf" flag
[thirdparty/man-pages.git] / man3 / asprintf.3
1 .\" Copyright (C) 2001 Andries Brouwer <aeb@cwi.nl>
2 .\"
3 .\" %%%LICENSE_START(VERBATIM)
4 .\" Permission is granted to make and distribute verbatim copies of this
5 .\" manual provided the copyright notice and this permission notice are
6 .\" preserved on all copies.
7 .\"
8 .\" Permission is granted to copy and distribute modified versions of this
9 .\" manual under the conditions for verbatim copying, provided that the
10 .\" entire resulting derived work is distributed under the terms of a
11 .\" permission notice identical to this one.
12 .\"
13 .\" Since the Linux kernel and libraries are constantly changing, this
14 .\" manual page may be incorrect or out-of-date. The author(s) assume no
15 .\" responsibility for errors or omissions, or for damages resulting from
16 .\" the use of the information contained herein. The author(s) may not
17 .\" have taken the same level of care in the production of this manual,
18 .\" which is licensed free of charge, as they might when working
19 .\" professionally.
20 .\"
21 .\" Formatted or processed versions of this manual, if unaccompanied by
22 .\" the source, must acknowledge the copyright and authors of this work.
23 .\" %%%LICENSE_END
24 .\"
25 .\" Text fragments inspired by Martin Schulze <joey@infodrom.org>.
26 .\"
27 .TH ASPRINTF 3 2019-03-06 "GNU" "Linux Programmer's Manual"
28 .SH NAME
29 asprintf, vasprintf \- print to allocated string
30 .SH SYNOPSIS
31 .BR "#define _GNU_SOURCE" " /* See feature_test_macros(7) */"
32 .br
33 .B #include <stdio.h>
34 .PP
35 .BI "int asprintf(char **" strp ", const char *" fmt ", ...);"
36 .PP
37 .BI "int vasprintf(char **" strp ", const char *" fmt ", va_list " ap );
38 .SH DESCRIPTION
39 The functions
40 .BR asprintf ()
41 and
42 .BR vasprintf ()
43 are analogs of
44 .BR sprintf (3)
45 and
46 .BR vsprintf (3),
47 except that they allocate a string large enough to hold the output
48 including the terminating null byte (\(aq\e0\(aq),
49 and return a pointer to it via the first argument.
50 This pointer should be passed to
51 .BR free (3)
52 to release the allocated storage when it is no longer needed.
53 .SH RETURN VALUE
54 When successful, these functions return the number of bytes printed,
55 just like
56 .BR sprintf (3).
57 If memory allocation wasn't possible, or some other error occurs,
58 these functions will return \-1, and the contents of
59 .I strp
60 are undefined.
61 .SH ATTRIBUTES
62 For an explanation of the terms used in this section, see
63 .BR attributes (7).
64 .TS
65 allbox;
66 lbw23 lb lb
67 l l l.
68 Interface Attribute Value
69 T{
70 .BR asprintf (),
71 .BR vasprintf ()
72 T} Thread safety MT-Safe locale
73 .TE
74 .sp 1
75 .SH CONFORMING TO
76 These functions are GNU extensions, not in C or POSIX.
77 They are also available under *BSD.
78 The FreeBSD implementation sets
79 .I strp
80 to NULL on error.
81 .SH SEE ALSO
82 .BR free (3),
83 .BR malloc (3),
84 .BR printf (3)