1 .\" $NetBSD: open_memstream.3,v 1.3 2014/10/26 14:19:28 christos Exp $
2 .\" Copyright (c) 2013 Advanced Computing Technologies LLC
3 .\" Written by: John H. Baldwin <jhb@FreeBSD.org>
4 .\" All rights reserved.
6 .\" Redistribution and use in source and binary forms, with or without
7 .\" modification, are permitted provided that the following conditions
9 .\" 1. Redistributions of source code must retain the above copyright
10 .\" notice, this list of conditions and the following disclaimer.
11 .\" 2. Redistributions in binary form must reproduce the above copyright
12 .\" notice, this list of conditions and the following disclaimer in the
13 .\" documentation and/or other materials provided with the distribution.
15 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 .\" $FreeBSD: head/lib/libc/stdio/open_memstream.3 247415 2013-02-27 20:09:25Z joel $
35 .Nd dynamic memory buffer stream open functions
41 .Fn open_memstream "char **bufp" "size_t *sizep"
44 .Fn open_wmemstream "wchar_t **bufp" "size_t *sizep"
50 functions create a write-only, seekable stream backed by a dynamically
51 allocated memory buffer.
54 function creates a byte-oriented stream,
57 function creates a wide-oriented stream.
59 Each stream maintains a current position and size.
61 the position and size are set to zero.
62 Each write begins at the current position and advances it the number of
63 successfully written bytes for
65 or wide characters for
67 If a write moves the current position beyond the length of the buffer,
68 the length of the buffer is extended and a null character is appended to the
71 A stream's buffer always contains a null character at the end of the buffer
72 that is not included in the current length.
74 If a stream's current position is moved beyond the current length via a
75 seek operation and a write is performed,
76 the characters between the current length and the current position are filled
77 with null characters before the write is performed.
79 After a successful call to
83 the pointer referenced by
85 will contain the start of the memory buffer and the variable referenced by
87 will contain the smaller of the current position and the current buffer length.
89 After a successful call to
91 the pointer referenced by
93 and the variable referenced by
95 are only valid until the next write operation or a call to
98 Once a stream is closed,
99 the allocated buffer referenced by
101 should be released via a call to
103 when it is no longer needed.
104 .Sh IMPLEMENTATION NOTES
105 Internally all I/O streams are effectively byte-oriented,
106 so using wide-oriented operations to write to a stream opened via
108 results in wide characters being expanded to a stream of multibyte characters
109 in stdio's internal buffers.
110 These multibyte characters are then converted back to wide characters when
111 written into the stream.
113 the wide-oriented streams maintain an internal multibyte character conversion
114 state that is cleared on any seek opertion that changes the current position.
115 This should have no effect as long as wide-oriented output operations are used
116 on a wide-oriented stream.
118 Upon successful completion,
127 is returned and the global variable
129 is set to indicate the error.
140 Memory for the stream or buffer could not be allocated.