xref: /minix3/lib/libc/stdio/open_memstream.3 (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc.\"	$NetBSD: open_memstream.3,v 1.3 2014/10/26 14:19:28 christos Exp $
2*0a6a1f1dSLionel Sambuc.\" Copyright (c) 2013 Advanced Computing Technologies LLC
3*0a6a1f1dSLionel Sambuc.\" Written by: John H. Baldwin <jhb@FreeBSD.org>
4*0a6a1f1dSLionel Sambuc.\" All rights reserved.
5*0a6a1f1dSLionel Sambuc.\"
6*0a6a1f1dSLionel Sambuc.\" Redistribution and use in source and binary forms, with or without
7*0a6a1f1dSLionel Sambuc.\" modification, are permitted provided that the following conditions
8*0a6a1f1dSLionel Sambuc.\" are met:
9*0a6a1f1dSLionel Sambuc.\" 1. Redistributions of source code must retain the above copyright
10*0a6a1f1dSLionel Sambuc.\"    notice, this list of conditions and the following disclaimer.
11*0a6a1f1dSLionel Sambuc.\" 2. Redistributions in binary form must reproduce the above copyright
12*0a6a1f1dSLionel Sambuc.\"    notice, this list of conditions and the following disclaimer in the
13*0a6a1f1dSLionel Sambuc.\"    documentation and/or other materials provided with the distribution.
14*0a6a1f1dSLionel Sambuc.\"
15*0a6a1f1dSLionel Sambuc.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16*0a6a1f1dSLionel Sambuc.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17*0a6a1f1dSLionel Sambuc.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18*0a6a1f1dSLionel Sambuc.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19*0a6a1f1dSLionel Sambuc.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20*0a6a1f1dSLionel Sambuc.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21*0a6a1f1dSLionel Sambuc.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22*0a6a1f1dSLionel Sambuc.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23*0a6a1f1dSLionel Sambuc.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24*0a6a1f1dSLionel Sambuc.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25*0a6a1f1dSLionel Sambuc.\" SUCH DAMAGE.
26*0a6a1f1dSLionel Sambuc.\"
27*0a6a1f1dSLionel Sambuc.\" $FreeBSD: head/lib/libc/stdio/open_memstream.3 247415 2013-02-27 20:09:25Z joel $
28*0a6a1f1dSLionel Sambuc.\"
29*0a6a1f1dSLionel Sambuc.Dd October 12, 2014
30*0a6a1f1dSLionel Sambuc.Dt OPEN_MEMSTREAM 3
31*0a6a1f1dSLionel Sambuc.Os
32*0a6a1f1dSLionel Sambuc.Sh NAME
33*0a6a1f1dSLionel Sambuc.Nm open_memstream ,
34*0a6a1f1dSLionel Sambuc.Nm open_wmemstream
35*0a6a1f1dSLionel Sambuc.Nd dynamic memory buffer stream open functions
36*0a6a1f1dSLionel Sambuc.Sh LIBRARY
37*0a6a1f1dSLionel Sambuc.Lb libc
38*0a6a1f1dSLionel Sambuc.Sh SYNOPSIS
39*0a6a1f1dSLionel Sambuc.In stdio.h
40*0a6a1f1dSLionel Sambuc.Ft FILE *
41*0a6a1f1dSLionel Sambuc.Fn open_memstream "char **bufp" "size_t *sizep"
42*0a6a1f1dSLionel Sambuc.In wchar.h
43*0a6a1f1dSLionel Sambuc.Ft FILE *
44*0a6a1f1dSLionel Sambuc.Fn open_wmemstream "wchar_t **bufp" "size_t *sizep"
45*0a6a1f1dSLionel Sambuc.Sh DESCRIPTION
46*0a6a1f1dSLionel SambucThe
47*0a6a1f1dSLionel Sambuc.Fn open_memstream
48*0a6a1f1dSLionel Sambucand
49*0a6a1f1dSLionel Sambuc.Fn open_wmemstream
50*0a6a1f1dSLionel Sambucfunctions create a write-only, seekable stream backed by a dynamically
51*0a6a1f1dSLionel Sambucallocated memory buffer.
52*0a6a1f1dSLionel SambucThe
53*0a6a1f1dSLionel Sambuc.Fn open_memstream
54*0a6a1f1dSLionel Sambucfunction creates a byte-oriented stream,
55*0a6a1f1dSLionel Sambucwhile the
56*0a6a1f1dSLionel Sambuc.Fn open_wmemstream
57*0a6a1f1dSLionel Sambucfunction creates a wide-oriented stream.
58*0a6a1f1dSLionel Sambuc.Pp
59*0a6a1f1dSLionel SambucEach stream maintains a current position and size.
60*0a6a1f1dSLionel SambucInitially,
61*0a6a1f1dSLionel Sambucthe position and size are set to zero.
62*0a6a1f1dSLionel SambucEach write begins at the current position and advances it the number of
63*0a6a1f1dSLionel Sambucsuccessfully written bytes for
64*0a6a1f1dSLionel Sambuc.Fn open_memstream
65*0a6a1f1dSLionel Sambucor wide characters for
66*0a6a1f1dSLionel Sambuc.Fn open_wmemstream .
67*0a6a1f1dSLionel SambucIf a write moves the current position beyond the length of the buffer,
68*0a6a1f1dSLionel Sambucthe length of the buffer is extended and a null character is appended to the
69*0a6a1f1dSLionel Sambucbuffer.
70*0a6a1f1dSLionel Sambuc.Pp
71*0a6a1f1dSLionel SambucA stream's buffer always contains a null character at the end of the buffer
72*0a6a1f1dSLionel Sambucthat is not included in the current length.
73*0a6a1f1dSLionel Sambuc.Pp
74*0a6a1f1dSLionel SambucIf a stream's current position is moved beyond the current length via a
75*0a6a1f1dSLionel Sambucseek operation and a write is performed,
76*0a6a1f1dSLionel Sambucthe characters between the current length and the current position are filled
77*0a6a1f1dSLionel Sambucwith null characters before the write is performed.
78*0a6a1f1dSLionel Sambuc.Pp
79*0a6a1f1dSLionel SambucAfter a successful call to
80*0a6a1f1dSLionel Sambuc.Xr fclose 3
81*0a6a1f1dSLionel Sambucor
82*0a6a1f1dSLionel Sambuc.Xr fflush 3 ,
83*0a6a1f1dSLionel Sambucthe pointer referenced by
84*0a6a1f1dSLionel Sambuc.Fa bufp
85*0a6a1f1dSLionel Sambucwill contain the start of the memory buffer and the variable referenced by
86*0a6a1f1dSLionel Sambuc.Fa sizep
87*0a6a1f1dSLionel Sambucwill contain the smaller of the current position and the current buffer length.
88*0a6a1f1dSLionel Sambuc.Pp
89*0a6a1f1dSLionel SambucAfter a successful call to
90*0a6a1f1dSLionel Sambuc.Xr fflush 3 ,
91*0a6a1f1dSLionel Sambucthe pointer referenced by
92*0a6a1f1dSLionel Sambuc.Fa bufp
93*0a6a1f1dSLionel Sambucand the variable referenced by
94*0a6a1f1dSLionel Sambuc.Fa sizep
95*0a6a1f1dSLionel Sambucare only valid until the next write operation or a call to
96*0a6a1f1dSLionel Sambuc.Xr fclose 3 .
97*0a6a1f1dSLionel Sambuc.Pp
98*0a6a1f1dSLionel SambucOnce a stream is closed,
99*0a6a1f1dSLionel Sambucthe allocated buffer referenced by
100*0a6a1f1dSLionel Sambuc.Fa bufp
101*0a6a1f1dSLionel Sambucshould be released via a call to
102*0a6a1f1dSLionel Sambuc.Xr free 3
103*0a6a1f1dSLionel Sambucwhen it is no longer needed.
104*0a6a1f1dSLionel Sambuc.Sh IMPLEMENTATION NOTES
105*0a6a1f1dSLionel SambucInternally all I/O streams are effectively byte-oriented,
106*0a6a1f1dSLionel Sambucso using wide-oriented operations to write to a stream opened via
107*0a6a1f1dSLionel Sambuc.Fn open_wmemstream
108*0a6a1f1dSLionel Sambucresults in wide characters being expanded to a stream of multibyte characters
109*0a6a1f1dSLionel Sambucin stdio's internal buffers.
110*0a6a1f1dSLionel SambucThese multibyte characters are then converted back to wide characters when
111*0a6a1f1dSLionel Sambucwritten into the stream.
112*0a6a1f1dSLionel SambucAs a result,
113*0a6a1f1dSLionel Sambucthe wide-oriented streams maintain an internal multibyte character conversion
114*0a6a1f1dSLionel Sambucstate that is cleared on any seek opertion that changes the current position.
115*0a6a1f1dSLionel SambucThis should have no effect as long as wide-oriented output operations are used
116*0a6a1f1dSLionel Sambucon a wide-oriented stream.
117*0a6a1f1dSLionel Sambuc.Sh RETURN VALUES
118*0a6a1f1dSLionel SambucUpon successful completion,
119*0a6a1f1dSLionel Sambuc.Fn open_memstream
120*0a6a1f1dSLionel Sambucand
121*0a6a1f1dSLionel Sambuc.Fn open_wmemstream
122*0a6a1f1dSLionel Sambucreturn a
123*0a6a1f1dSLionel Sambuc.Tn FILE
124*0a6a1f1dSLionel Sambucpointer.
125*0a6a1f1dSLionel SambucOtherwise,
126*0a6a1f1dSLionel Sambuc.Dv NULL
127*0a6a1f1dSLionel Sambucis returned and the global variable
128*0a6a1f1dSLionel Sambuc.Va errno
129*0a6a1f1dSLionel Sambucis set to indicate the error.
130*0a6a1f1dSLionel Sambuc.Sh ERRORS
131*0a6a1f1dSLionel Sambuc.Bl -tag -width Er
132*0a6a1f1dSLionel Sambuc.It Bq Er EINVAL
133*0a6a1f1dSLionel SambucThe
134*0a6a1f1dSLionel Sambuc.Fa bufp
135*0a6a1f1dSLionel Sambucor
136*0a6a1f1dSLionel Sambuc.Fa sizep
137*0a6a1f1dSLionel Sambucargument was
138*0a6a1f1dSLionel Sambuc.Dv NULL .
139*0a6a1f1dSLionel Sambuc.It Bq Er ENOMEM
140*0a6a1f1dSLionel SambucMemory for the stream or buffer could not be allocated.
141*0a6a1f1dSLionel Sambuc.El
142*0a6a1f1dSLionel Sambuc.Sh SEE ALSO
143*0a6a1f1dSLionel Sambuc.Xr fclose 3 ,
144*0a6a1f1dSLionel Sambuc.Xr fflush 3 ,
145*0a6a1f1dSLionel Sambuc.Xr fopen 3 ,
146*0a6a1f1dSLionel Sambuc.Xr free 3 ,
147*0a6a1f1dSLionel Sambuc.Xr fseek 3 ,
148*0a6a1f1dSLionel Sambuc.Xr stdio 3
149*0a6a1f1dSLionel Sambuc.Sh STANDARDS
150*0a6a1f1dSLionel SambucThe
151*0a6a1f1dSLionel Sambuc.Fn open_memstream
152*0a6a1f1dSLionel Sambucand
153*0a6a1f1dSLionel Sambuc.Fn open_wmemstream
154*0a6a1f1dSLionel Sambucfunctions conform to
155*0a6a1f1dSLionel Sambuc.St -p1003.1-2008 .
156