These functions allow string buffers to be read and written as streams.
creates a read-only stream that reads from the buffer pointed to by
is non-zero, the contents of the buffer are copied and therefore
doesnt need to remain valid while the stream is open.
Otherwise, the data pointed to by
is not copied and must remain valid while the stream is open.
should be used to close the stream.
creates a write-only stream that writes into an internal buffer that
should be used to close the stream; this also frees the internal buffer.
The current buffer length is returned by
returns the contents of the internal buffer.
argument must be a stream created by
is zero, then the internal buffer remains valid and the returned pointer
should be treated as read-only and not be freed; it also becomes invalid
with the next operation on the stream.
is non-zero, the current buffer contents are "detached" and returned by
and a new, empty internal buffer is created; in this case, the caller is
responsible for eventually freeing the returned buffer,
which is allocated with
and its contents remain valid until then.
In either case, the data returned by
is guaranteed to have one additional \0 byte appended.
Therefore, it is always safe to treat this pointer as a normal C string.
However, any \0 bytes previously written to the stream will cause
this string to appear truncated.