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