open_memstream(), open_wmemstream()

copy string 

Function


SYNOPSIS

#include <stdio.h>

FILE *open_memstream(char **bufp, size_t *sizep);

#include <wchar.h>

FILE *open_wmemstream(char **bufp, size_t *sizep);


DESCRIPTION

The open_memstream() and open_wmemstream() functions create a write-only, seekable stream backed by a dynamically allocated memory buffer. The open_memstream() function creates a byte-oriented stream, while the open_wmemstream() function creates a wide-oriented stream. Each stream maintains a current position and size. Initially, the position and size are set to zero. Each write begins at the current position and advances it the number of successfully written bytes for open_memstream() or wide characters for open_wmemstream(). If a write moves the current position beyond the length of the buffer, the length of the buffer is extended and a null character is appended to the buffer. A stream's buffer always contains a null character at the end of the buffer that is not included in the current length. If a stream's current position is moved beyond the current length via a seek operation and a write is performed, the characters between the current length and the current position are filled with null characters before the write is performed. After a successful call to fclose() or fflush(), the pointer referenced by bufp will contain the start of the memory buffer and the variable referenced by sizep will contain the smaller of the current position and the current buffer length. After a successful call to fflush(), the pointer referenced by bufp and the variable referenced by sizep are only valid until the next write operation or a call to fclose(). Once a stream is closed, the allocated buffer referenced by bufp should be released via a call to free() when it is no longer needed.


RETURN VALUE

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.

EINVAL 

The bufp or sizep argument was NULL.

ENOMEM 

Memory for the stream or buffer could not be allocated.


CONFORMANCE

IEEE Std 1003.1-2008 'POSIX.1'


MULTITHREAD SAFETY LEVEL

MT-Safe.


PORTING ISSUES

None.


AVAILABILITY

PTC MKS Toolkit for Professional Developers
PTC MKS Toolkit for Professional Developers 64-Bit Edition
PTC MKS Toolkit for Enterprise Developers
PTC MKS Toolkit for Enterprise Developers 64-Bit Edition


SEE ALSO

Functions:
fclose(), fflush(), fopen(), free(), fseek()


PTC MKS Toolkit 10.3 Documentation Build 39.