]>
Commit | Line | Data |
---|---|---|
fea681da MK |
1 | .\" Copyright (C) 2001 Andries Brouwer <aeb@cwi.nl> |
2 | .\" | |
93015253 | 3 | .\" %%%LICENSE_START(VERBATIM) |
fea681da MK |
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. | |
c13182ef | 12 | .\" |
fea681da MK |
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. | |
c13182ef | 20 | .\" |
fea681da MK |
21 | .\" Formatted or processed versions of this manual, if unaccompanied by |
22 | .\" the source, must acknowledge the copyright and authors of this work. | |
4b72fb64 | 23 | .\" %%%LICENSE_END |
fea681da MK |
24 | .\" |
25 | .\" Text fragments inspired by Martin Schulze <joey@infodrom.org>. | |
26 | .\" | |
4b8c67d9 | 27 | .TH ASPRINTF 3 2017-09-15 "GNU" "Linux Programmer's Manual" |
fea681da MK |
28 | .SH NAME |
29 | asprintf, vasprintf \- print to allocated string | |
30 | .SH SYNOPSIS | |
b80f966b | 31 | .BR "#define _GNU_SOURCE" " /* See feature_test_macros(7) */" |
fea681da MK |
32 | .br |
33 | .B #include <stdio.h> | |
68e4db0a | 34 | .PP |
fea681da | 35 | .BI "int asprintf(char **" strp ", const char *" fmt ", ...);" |
68e4db0a | 36 | .PP |
fea681da MK |
37 | .BI "int vasprintf(char **" strp ", const char *" fmt ", va_list " ap ); |
38 | .SH DESCRIPTION | |
39 | The functions | |
e511ffb6 | 40 | .BR asprintf () |
fea681da | 41 | and |
e511ffb6 | 42 | .BR vasprintf () |
d9bfdb9c | 43 | are analogs of |
fb186734 | 44 | .BR sprintf (3) |
fea681da | 45 | and |
fb186734 | 46 | .BR vsprintf (3), |
fea681da | 47 | except that they allocate a string large enough to hold the output |
f24e3a3a | 48 | including the terminating null byte (\(aq\\0\(aq), |
c4bb193f | 49 | and return a pointer to it via the first argument. |
fea681da MK |
50 | This pointer should be passed to |
51 | .BR free (3) | |
52 | to release the allocated storage when it is no longer needed. | |
47297adb | 53 | .SH RETURN VALUE |
fea681da MK |
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 | |
95748d53 | 60 | are undefined. |
0f6cf80d ZL |
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 | |
847e0d88 | 74 | .sp 1 |
a7fadb55 | 75 | .SH CONFORMING TO |
fea681da MK |
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. | |
47297adb | 81 | .SH SEE ALSO |
fea681da MK |
82 | .BR free (3), |
83 | .BR malloc (3), | |
0a4f8b7b | 84 | .BR printf (3) |