NAME
open_memstream
,
open_wmemstream
—
open a memory buffer stream
SYNOPSIS
#include
<stdio.h>
FILE *
open_memstream
(char
**pbuf, size_t
*psize);
#include
<wchar.h>
FILE *
open_wmemstream
(wchar_t
**pbuf, size_t
*psize);
DESCRIPTION
The
open_memstream
()
and
open_wmemstream
()
functions create, respectively, a seekable byte-oriented or wide-oriented
stream for writing. A dynamically allocated buffer, using
malloc(3),
is then wrapped to the pointer referenced by pbuf and
grows automatically as required.
When the stream is either closed or flushed, the address of the buffer is stored in the pointer referenced by pbuf. At the same time the smaller of the current position and the buffer length is written in the variable pointed to by psize. This value represents, respectively, the number of bytes or wide characters contained in the buffer, not including the terminating null character.
The buffer memory should be released after the stream is closed.
RETURN VALUES
Upon successful completion,
open_memstream
() and
open_wmemstream
() return a
FILE
pointer. Otherwise,
NULL
is returned and the global variable
errno is set to indicate the error.
ERRORS
- [
EINVAL
] - The pbuf or the psize argument
is
NULL
.
The open_memstream
() and
open_wmemstream
() functions may also fail and set
errno for any of the errors specified for the routine
malloc(3).
SEE ALSO
STANDARDS
The functions open_memstream
() and
open_wmemstream
(), conform to IEEE
Std 1003.1-2008 (“POSIX.1”).
HISTORY
The open_memstream
() and
open_wmemstream
() functions first appeared in
OpenBSD 5.4.