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