OSDN Git Service

LDP: Update original to LDP v3.79
[linuxjm/LDP_man-pages.git] / original / 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 2013-06-21 "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 .sp
35 .BI "int asprintf(char **" strp ", const char *" fmt ", ...);"
36 .sp
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\\0\(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 is undefined.
61 .SH CONFORMING TO
62 These functions are GNU extensions, not in C or POSIX.
63 They are also available under *BSD.
64 The FreeBSD implementation sets
65 .I strp
66 to NULL on error.
67 .SH SEE ALSO
68 .BR free (3),
69 .BR malloc (3),
70 .BR printf (3)
71 .SH COLOPHON
72 This page is part of release 3.79 of the Linux
73 .I man-pages
74 project.
75 A description of the project,
76 information about reporting bugs,
77 and the latest version of this page,
78 can be found at
79 \%http://www.kernel.org/doc/man\-pages/.