fmemopen()

associate stream with a buffer 

Function


SYNOPSIS

#include <stdio.h>

FILE *fmemopen(void **buf, size_t size, const char *type);


DESCRIPTION

The fmemopen() function associates the buffer given by the buf and size arguments with a stream. The buf argument is either a null pointer or a pointer to a buffer that is at least size bytes long. If a null pointer is specified as the buf argument, fmemopen() allocates size bytes of memory, and this allocation is automatically freed when the stream is closed. If a non-null pointer is specified, the caller retains ownership of the buffer and is responsible for disposing of it after the stream has been closed. Buffers can be opened in text-mode (default) or binary-mode (if "b" is present in the second or third position of the type argument). Buffers opened in text-mode make sure that writes are terminated with a NULL byte, if the last write hasn't filled up the whole buffer. Buffers opened in binary-mode never append a NULL byte.

The file position indicator associated with the new stream is set to the start of the buffer.


PARAMETERS

buf 

Indicates the user buffer or NULL for system allocation.

size 

The size in bytes of the buffer passed, or the size to allocate if NULL is passed.

type 

Indicates a character string that specifies the desired type of file access. The first character of this string must be one of r (open for reading), w (open for writing), or a (open for writing at the end of file —append). After the first character, you can also add the + modifier that means to open for update, both reading and writing. The meaning of these flags is exactly as specified for fopen(), except that w and w+ do not cause truncation of the file.


RETURN VALUES

If successful, fmemopen() returns a pointer to a stream. On failure, it returns a NULL pointer and errno is set to one of the following values:

EINVAL 

The value of the type argument is invalid.

ENOMEM 

Insufficient storage space is available.


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:
close(), creat(), dup(), fclose(), fdopen(), fopen(), freopen(), fseek(), open(), pipe(), write()


PTC MKS Toolkit 10.3 Documentation Build 39.