mount_setattr.2: Minor tweaks to Christian's patch
[man-pages.git] / man3 / open_memstream.3
blobea1489cb81dceed48ffc5827bbd8e8cc96d285e2
1 .\" Copyright 2005, 2012, 2016 Michael Kerrisk <mtk.manpages@gmail.com>
2 .\"
3 .\" %%%LICENSE_START(GPL_NOVERSION_ONELINE)
4 .\" Distributed under the GPL.
5 .\" %%%LICENSE_END
6 .\"
7 .\" 2008-12-04, Petr Baudis <pasky@suse.cz>: Document open_wmemstream()
8 .\"
9 .TH OPEN_MEMSTREAM 3 2021-03-22 "GNU" "Linux Programmer's Manual"
10 .SH NAME
11 open_memstream, open_wmemstream \-  open a dynamic memory buffer stream
12 .SH SYNOPSIS
13 .nf
14 .B #include <stdio.h>
15 .PP
16 .BI "FILE *open_memstream(char **" ptr ", size_t *" sizeloc );
17 .PP
18 .B #include <wchar.h>
19 .PP
20 .BI "FILE *open_wmemstream(wchar_t **" ptr ", size_t *" sizeloc );
21 .fi
22 .PP
23 .RS -4
24 Feature Test Macro Requirements for glibc (see
25 .BR feature_test_macros (7)):
26 .RE
27 .PP
28 .BR open_memstream (),
29 .BR open_wmemstream ():
30 .nf
31     Since glibc 2.10:
32         _POSIX_C_SOURCE >= 200809L
33     Before glibc 2.10:
34         _GNU_SOURCE
35 .fi
36 .SH DESCRIPTION
37 The
38 .BR open_memstream ()
39 function opens a stream for writing to a memory buffer.
40 The function dynamically allocates the buffer,
41 and the buffer automatically grows as needed.
42 Initially, the buffer has a size of zero.
43 After closing the stream, the caller should
44 .BR free (3)
45 this buffer.
46 .PP
47 The locations pointed to by
48 .IR ptr
49 and
50 .I sizeloc
51 are used to report, respectively,
52 the current location and the size of the buffer.
53 The locations referred to by these pointers are updated
54 each time the stream is flushed
55 .RB ( fflush (3))
56 and when the stream is closed
57 .RB ( fclose (3)).
58 These values remain valid only as long as the caller
59 performs no further output on the stream.
60 If further output is performed, then the stream
61 must again be flushed before trying to access these values.
62 .PP
63 A null byte is maintained at the end of the buffer.
64 This byte is
65 .I not
66 included in the size value stored at
67 .IR sizeloc .
68 .PP
69 The stream maintains the notion of a current position,
70 which is initially zero (the start of the buffer).
71 Each write operation implicitly adjusts the buffer position.
72 The stream's buffer position can be explicitly changed with
73 .BR fseek (3)
75 .BR fseeko (3).
76 Moving the buffer position past the end
77 of the data already written fills the intervening space with
78 null characters.
79 .PP
80 The
81 .BR open_wmemstream ()
82 is similar to
83 .BR open_memstream (),
84 but operates on wide characters instead of bytes.
85 .SH RETURN VALUE
86 Upon successful completion,
87 .BR open_memstream ()
88 and
89 .BR open_wmemstream ()
90 return a
91 .I FILE
92 pointer.
93 Otherwise, NULL is returned and
94 .I errno
95 is set to indicate the error.
96 .SH VERSIONS
97 .BR open_memstream ()
98 was already available in glibc 1.0.x.
99 .BR open_wmemstream ()
100 is available since glibc 2.4.
101 .SH ATTRIBUTES
102 For an explanation of the terms used in this section, see
103 .BR attributes (7).
104 .ad l
107 allbox;
108 lbx lb lb
109 l l l.
110 Interface       Attribute       Value
112 .BR open_memstream (),
113 .BR open_wmemstream ()
114 T}      Thread safety   MT-Safe
118 .sp 1
119 .SH CONFORMING TO
120 POSIX.1-2008.
121 These functions are not specified in POSIX.1-2001,
122 and are not widely available on other systems.
123 .SH NOTES
124 There is no file descriptor associated with the file stream
125 returned by these functions
126 (i.e.,
127 .BR fileno (3)
128 will return an error if called on the returned stream).
129 .SH BUGS
130 In glibc before version 2.7, seeking past the end of a stream created by
131 .BR open_memstream ()
132 does not enlarge the buffer; instead the
133 .BR fseek (3)
134 call fails, returning \-1.
135 .\" http://sourceware.org/bugzilla/show_bug.cgi?id=1996
136 .SH EXAMPLES
138 .BR fmemopen (3).
139 .SH SEE ALSO
140 .BR fmemopen (3),
141 .BR fopen (3),
142 .BR setbuf (3)