Section (3) open_memstream
open_memstream, open_wmemstream — open a dynamic memory buffer stream
function opens a stream for writing to a memory buffer. The
function dynamically allocates the buffer, and the buffer
automatically grows as needed. Initially, the buffer has a
size of zero. After closing the stream, the caller should
free(3) this buffer.
The locations pointed to by
sizeloc are used to report,
respectively, the current location and the size of the
buffer. The locations referred to by these pointers are
updated each time the stream is flushed (fflush(3)) and when the
stream is closed (fclose(3)). These values
remain valid only as long as the caller performs no further
output on the stream. If further output is performed, then
the stream must again be flushed before trying to access
A null byte is maintained at the end of the buffer. This
byte is not included
in the size value stored at
The stream maintains the notion of a current position, which is initially zero (the start of the buffer). Each write operation implicitly adjusts the buffer position. The stream_zsingle_quotesz_s buffer position can be explicitly changed with fseek(3) or fseeko(3). Moving the buffer position past the end of the data already written fills the intervening space with null characters.
but operates on wide characters instead of bytes.
Upon successful completion,
open_wmemstream() return a FILE pointer. Otherwise, NULL is returned and
errno is set to indicate the
open_memstream() was already
available in glibc 1.0.x.
open_wmemstream() is available since glibc
For an explanation of the terms used in this section, see attributes(7).
POSIX.1-2008. These functions are not specified in POSIX.1-2001, and are not widely available on other systems.
There is no file descriptor associated with the file stream returned by these functions (i.e., fileno(3) will return an error if called on the returned stream).
In glibc before version 2.7, seeking past the end of a
stream created by
open_memstream() does not enlarge the
buffer; instead the fseek(3) call fails,
This page is part of release 4.16 of the Linux
man-pages project. A
description of the project, information about reporting bugs,
and the latest version of this page, can be found at
Copyright 2005, 2012, 2016 Michael Kerrisk <mtk.manpagesgmail.com>
Distributed under the GPL.
2008-12-04, Petr Baudis <paskysuse.cz>: Document open_wmemstream()