|FMEMOPEN(3)||Library Functions Manual||FMEMOPEN(3)|
size, const char
fmemopen() function associates a stream with the given buffer and size. The buffer can be either
NULL, or must be of the given size. If the buffer is
NULL, a buffer of the given size will be dynamically allocated using malloc(3) and released when fclose(3) is called.
The mode argument has the same meaning as in fopen(3).
The stream treats the buffer as it would treat a file tracking the
current position to perform I/O operations. For example, in the beginning
the stream points to the beginning of the buffer, unless ‘a’
was specified in the mode argument, and then it points
to the first
NUL byte. If a
NULL buffer was specified,
then the stream will always point at the first byte of the
The stream also keeps track of the size of the buffer. The size is initialized depending on the mode:
Read or write operations advance the buffer, but not to exceed the
given size of the buffer. Trying
to read beyond the size of the
buffer results in
NUL bytes are read normally. Trying to
write beyond the size of the
buffer has no effect.
When a stream open for writing is either flushed or closed, a
NUL byte is written at the current position or at
the end of the current size as kept internally.
fmemopen() returns a
NULLis returned and the global variable errno is set to indicate the error.
0; or the mode argument is invalid; or the buffer argument is
NULLand the mode argument does not specify a ‘+’.
fmemopen() function may also fail and
set errno for any of the errors specified for the
fmemopen() conform to IEEE Std 1003.1-2008 (“POSIX.1”).
fmemopen() function first appeared in OpenBSD 5.4.
|June 5, 2013||OpenBSD-current|