Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

open_wmemstream(3) [freebsd man page]

OPEN_MEMSTREAM(3)					   BSD Library Functions Manual 					 OPEN_MEMSTREAM(3)

open_memstream, open_wmemstream -- dynamic memory buffer stream open functions LIBRARY
Standard C Library (libc, -lc) SYNOPSIS
#include <stdio.h> FILE * open_memstream(char **bufp, size_t *sizep); #include <wchar.h> FILE * open_wmemstream(wchar_t **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 posi- tion 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 buf- fer. 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(3) or fflush(3), the pointer referenced by bufp will contain the start of the memory buffer and the vari- able referenced by sizep will contain the smaller of the current position and the current buffer length. After a successful call to fflush(3,) the pointer referenced by bufp and the variable referenced by sizep are only valid until the next write operation or a call to fclose(3.) Once a stream is closed, the allocated buffer referenced by bufp should be released via a call to free(3) when it is no longer needed. IMPLEMENTATION NOTES
Internally all I/O streams are effectively byte-oriented, so using wide-oriented operations to write to a stream opened via open_wmemstream() results in wide characters being expanded to a stream of multibyte characters in stdio's internal buffers. These multibyte characters are then converted back to wide characters when written into the stream. As a result, the wide-oriented streams maintain an internal multibyte character conversion state that is cleared on any seek opertion that changes the current position. This should have no effect as long as wide-oriented output operations are used on a wide-oriented stream. RETURN VALUES
Upon successful completion, open_memstream() and open_wmemstream() return a FILE pointer. Otherwise, NULL is returned and the global vari- able errno is set to indicate the error. ERRORS
[EINVAL] The bufp or sizep argument was NULL. [ENOMEM] Memory for the stream or buffer could not be allocated. SEE ALSO
fclose(3), fflush(3), fopen(3), free(3), fseek(3), sbuf(3), stdio(3) STANDARDS
The open_memstream() and open_wmemstream() functions conform to IEEE Std 1003.1-2008 (``POSIX.1''). BSD
October 28, 2014 BSD

Check Out this Related Man Page

OPEN_MEMSTREAM(3)                                            Linux Programmer's Manual                                           OPEN_MEMSTREAM(3)

open_memstream, open_wmemstream - open a dynamic memory buffer stream SYNOPSIS
#include <stdio.h> FILE *open_memstream(char **ptr, size_t *sizeloc); #include <wchar.h> FILE *open_wmemstream(wchar_t **ptr, size_t *sizeloc); Feature Test Macro Requirements for glibc (see feature_test_macros(7)): open_memstream(), open_wmemstream(): Since glibc 2.10: _POSIX_C_SOURCE >= 200809L Before glibc 2.10: _GNU_SOURCE DESCRIPTION
The open_memstream() function opens a stream for writing to a memory buffer. The function dynamically allocates the buffer, and the buffer automatically grows as needed. Initially, the buffer has a size of zero. After closing the stream, the caller should free(3) this buffer. The locations pointed to by ptr and sizeloc are used to report, respectively, the current location and the size of the buffer. The loca- tions referred to by these pointers are updated each time the stream is flushed (fflush(3)) and when the stream is closed (fclose(3)). These values remain valid only as long as the caller performs no further output on the stream. If further output is performed, then the stream must again be flushed before trying to access these values. A null byte is maintained at the end of the buffer. This byte is not included in the size value stored at sizeloc. The stream maintains the notion of a current position, which is initially zero (the start of the buffer). Each write operation implicitly adjusts the buffer position. The stream's buffer position can be explicitly changed with fseek(3) or fseeko(3). Moving the buffer posi- tion past the end of the data already written fills the intervening space with null characters. The open_wmemstream() is similar to open_memstream(), but operates on wide characters instead of bytes. RETURN VALUE
Upon successful completion, open_memstream() and open_wmemstream() return a FILE pointer. Otherwise, NULL is returned and errno is set to indicate the error. VERSIONS
open_memstream() was already available in glibc 1.0.x. open_wmemstream() is available since glibc 2.4. ATTRIBUTES
For an explanation of the terms used in this section, see attributes(7). +------------------+---------------+---------+ |Interface | Attribute | Value | +------------------+---------------+---------+ |open_memstream(), | Thread safety | MT-Safe | |open_wmemstream | | | +------------------+---------------+---------+ CONFORMING TO
POSIX.1-2008. These functions are not specified in POSIX.1-2001, and are not widely available on other systems. NOTES
There is no file descriptor associated with the file stream returned by these functions (i.e., fileno(3) will return an error if called on the returned stream). BUGS
In glibc before version 2.7, seeking past the end of a stream created by open_memstream() does not enlarge the buffer; instead the fseek(3) call fails, returning -1. EXAMPLE
See fmemopen(3). SEE ALSO
fmemopen(3), fopen(3), setbuf(3) COLOPHON
This page is part of release 4.15 of the Linux man-pages project. A description of the project, information about reporting bugs, and the latest version of this page, can be found at GNU 2017-09-15 OPEN_MEMSTREAM(3)
Man Page