]> git.ipfire.org Git - thirdparty/man-pages.git/blame - man3/asprintf.3
_exit.2, bpf.2, cacheflush.2, capget.2, chdir.2, chmod.2, chroot.2, clock_getres...
[thirdparty/man-pages.git] / man3 / asprintf.3
CommitLineData
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.\"
c73595c2 27.TH ASPRINTF 3 2015-04-19 "GNU" "Linux Programmer's Manual"
fea681da
MK
28.SH NAME
29asprintf, 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
39The functions
e511ffb6 40.BR asprintf ()
fea681da 41and
e511ffb6 42.BR vasprintf ()
d9bfdb9c 43are analogs of
fb186734 44.BR sprintf (3)
fea681da 45and
fb186734 46.BR vsprintf (3),
fea681da 47except that they allocate a string large enough to hold the output
f24e3a3a 48including the terminating null byte (\(aq\\0\(aq),
c4bb193f 49and return a pointer to it via the first argument.
fea681da
MK
50This pointer should be passed to
51.BR free (3)
52to release the allocated storage when it is no longer needed.
47297adb 53.SH RETURN VALUE
fea681da
MK
54When successful, these functions return the number of bytes printed,
55just like
56.BR sprintf (3).
57If memory allocation wasn't possible, or some other error occurs,
58these functions will return \-1, and the contents of
59.I strp
95748d53 60are undefined.
0f6cf80d
ZL
61.SH ATTRIBUTES
62For an explanation of the terms used in this section, see
63.BR attributes (7).
64.TS
65allbox;
66lbw23 lb lb
67l l l.
68Interface Attribute Value
69T{
70.BR asprintf (),
71.BR vasprintf ()
72T} Thread safety MT-Safe locale
73.TE
74
a7fadb55 75.SH CONFORMING TO
fea681da
MK
76These functions are GNU extensions, not in C or POSIX.
77They are also available under *BSD.
78The FreeBSD implementation sets
79.I strp
80to NULL on error.
47297adb 81.SH SEE ALSO
fea681da
MK
82.BR free (3),
83.BR malloc (3),
0a4f8b7b 84.BR printf (3)