mount_setattr.2: Further tweaks after feedback from Christian Brauner
[man-pages.git] / man3 / asprintf.3
blob09b89a34de1994057a4225394499bd6ce7f4f5fd
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 2021-03-22 "GNU" "Linux Programmer's Manual"
28 .SH NAME
29 asprintf, vasprintf \- print to allocated string
30 .SH SYNOPSIS
31 .nf
32 .BR "#define _GNU_SOURCE" "         /* See feature_test_macros(7) */"
33 .B #include <stdio.h>
34 .PP
35 .BI "int asprintf(char **restrict " strp ", const char *restrict " fmt ", ...);"
36 .BI "int vasprintf(char **restrict " strp ", const char *restrict " fmt ,
37 .BI "              va_list " ap );
38 .fi
39 .SH DESCRIPTION
40 The functions
41 .BR asprintf ()
42 and
43 .BR vasprintf ()
44 are analogs of
45 .BR sprintf (3)
46 and
47 .BR vsprintf (3),
48 except that they allocate a string large enough to hold the output
49 including the terminating null byte (\(aq\e0\(aq),
50 and return a pointer to it via the first argument.
51 This pointer should be passed to
52 .BR free (3)
53 to release the allocated storage when it is no longer needed.
54 .SH RETURN VALUE
55 When successful, these functions return the number of bytes printed,
56 just like
57 .BR sprintf (3).
58 If memory allocation wasn't possible, or some other error occurs,
59 these functions will return \-1, and the contents of
60 .I strp
61 are undefined.
62 .SH ATTRIBUTES
63 For an explanation of the terms used in this section, see
64 .BR attributes (7).
65 .ad l
66 .nh
67 .TS
68 allbox;
69 lbx lb lb
70 l l l.
71 Interface       Attribute       Value
73 .BR asprintf (),
74 .BR vasprintf ()
75 T}      Thread safety   MT-Safe locale
76 .TE
77 .hy
78 .ad
79 .sp 1
80 .SH CONFORMING TO
81 These functions are GNU extensions, not in C or POSIX.
82 They are also available under *BSD.
83 The FreeBSD implementation sets
84 .I strp
85 to NULL on error.
86 .SH SEE ALSO
87 .BR free (3),
88 .BR malloc (3),
89 .BR printf (3)