OpenBSD manual page server

Manual Page Search Parameters

OPEN_MEMSTREAM(3) Library Functions Manual OPEN_MEMSTREAM(3)

open_memstream, open_wmemstreamopen a memory buffer stream

#include <stdio.h>

FILE *
open_memstream(char **pbuf, size_t *psize);

#include <wchar.h>

FILE *
open_wmemstream(wchar_t **pbuf, size_t *psize);

The () and () 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.

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.

[]
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).

fmemopen(3), fopen(3), funopen(3), malloc(3)

The functions open_memstream() and open_wmemstream(), conform to IEEE Std 1003.1-2008 (“POSIX.1”).

The open_memstream() and open_wmemstream() functions first appeared in OpenBSD 5.4.

June 5, 2013 OpenBSD-7.2