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