open_memstream(3) — Linux manual page

NAME | LIBRARY | SYNOPSIS | DESCRIPTION | RETURN VALUE | ATTRIBUTES | STANDARDS | HISTORY | NOTES | BUGS | EXAMPLES | SEE ALSO | COLOPHON

open_memstream(3)       Library Functions Manual       open_memstream(3)

NAME         top

       open_memstream, open_wmemstream - open a dynamic memory buffer
       stream

LIBRARY         top

       Standard C library (libc, -lc)

SYNOPSIS         top

       #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         top

       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 locations 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 position 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         top

       Upon successful completion, open_memstream() and
       open_wmemstream() return a FILE pointer.  Otherwise, NULL is
       returned and errno is set to indicate the error.

ATTRIBUTES         top

       For an explanation of the terms used in this section, see
       attributes(7).
       ┌─────────────────────────────────────┬───────────────┬─────────┐
       │ Interface                           Attribute     Value   │
       ├─────────────────────────────────────┼───────────────┼─────────┤
       │ open_memstream(), open_wmemstream() │ Thread safety │ MT-Safe │
       └─────────────────────────────────────┴───────────────┴─────────┘

STANDARDS         top

       POSIX.1-2008.

HISTORY         top

       open_memstream()
              glibc 1.0.x.

       open_wmemstream()
              glibc 2.4.

NOTES         top

       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         top

       Before glibc 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.

EXAMPLES         top

       See fmemopen(3).

SEE ALSO         top

       fmemopen(3), fopen(3), setbuf(3)

COLOPHON         top

       This page is part of the man-pages (Linux kernel and C library
       user-space interface documentation) project.  Information about
       the project can be found at 
       ⟨https://www.kernel.org/doc/man-pages/⟩.  If you have a bug report
       for this manual page, see
       ⟨https://git.kernel.org/pub/scm/docs/man-pages/man-pages.git/tree/CONTRIBUTING⟩.
       This page was obtained from the tarball man-pages-6.9.1.tar.gz
       fetched from
       ⟨https://mirrors.edge.kernel.org/pub/linux/docs/man-pages/⟩ on
       2024-06-26.  If you discover any rendering problems in this HTML
       version of the page, or you believe there is a better or more up-
       to-date source for the page, or you have corrections or
       improvements to the information in this COLOPHON (which is not
       part of the original manual page), send a mail to
       [email protected]

Linux man-pages 6.9.1          2024-05-02              open_memstream(3)

Pages that refer to this page: fmemopen(3)fopen(3)malloc_info(3)stdio(3)