242 lines
5.7 KiB
HTML
242 lines
5.7 KiB
HTML
|
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
|
<HTML><HEAD><TITLE>Man page of OPEN_MEMSTREAM</TITLE>
|
|
</HEAD><BODY>
|
|
<H1>OPEN_MEMSTREAM</H1>
|
|
Section: Linux Programmer's Manual (3)<BR>Updated: 2017-09-15<BR><A HREF="#index">Index</A>
|
|
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
|
|
|
|
<A NAME="lbAB"> </A>
|
|
<H2>NAME</H2>
|
|
|
|
open_memstream, open_wmemstream - open a dynamic memory buffer stream
|
|
<A NAME="lbAC"> </A>
|
|
<H2>SYNOPSIS</H2>
|
|
|
|
<PRE>
|
|
<B>#include <<A HREF="file:///usr/include/stdio.h">stdio.h</A>></B>
|
|
|
|
<B>FILE *open_memstream(char **</B><I>ptr</I><B>, size_t *</B><I>sizeloc</I><B>);</B>
|
|
|
|
<B>#include <<A HREF="file:///usr/include/wchar.h">wchar.h</A>></B>
|
|
|
|
<B>FILE *open_wmemstream(wchar_t **</B><I>ptr</I><B>, size_t *</B><I>sizeloc</I><B>);</B>
|
|
</PRE>
|
|
|
|
<P>
|
|
|
|
|
|
Feature Test Macro Requirements for glibc (see
|
|
<B><A HREF="/cgi-bin/man/man2html?7+feature_test_macros">feature_test_macros</A></B>(7)):
|
|
|
|
|
|
<P>
|
|
|
|
<B>open_memstream</B>(),
|
|
|
|
<B>open_wmemstream</B>():
|
|
|
|
|
|
|
|
<DL COMPACT><DT id="1"><DD>
|
|
<DL COMPACT>
|
|
<DT id="2">Since glibc 2.10:<DD>
|
|
_POSIX_C_SOURCE >= 200809L
|
|
<DT id="3">Before glibc 2.10:<DD>
|
|
_GNU_SOURCE
|
|
</DL>
|
|
</DL>
|
|
|
|
|
|
|
|
<A NAME="lbAD"> </A>
|
|
<H2>DESCRIPTION</H2>
|
|
|
|
The
|
|
<B>open_memstream</B>()
|
|
|
|
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
|
|
<B><A HREF="/cgi-bin/man/man2html?3+free">free</A></B>(3)
|
|
|
|
this buffer.
|
|
<P>
|
|
|
|
The locations pointed to by
|
|
<I>ptr</I>
|
|
|
|
and
|
|
<I>sizeloc</I>
|
|
|
|
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
|
|
(<B><A HREF="/cgi-bin/man/man2html?3+fflush">fflush</A></B>(3))
|
|
|
|
and when the stream is closed
|
|
(<B><A HREF="/cgi-bin/man/man2html?3+fclose">fclose</A></B>(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.
|
|
<P>
|
|
|
|
A null byte is maintained at the end of the buffer.
|
|
This byte is
|
|
<I>not</I>
|
|
|
|
included in the size value stored at
|
|
<I>sizeloc</I>.
|
|
|
|
<P>
|
|
|
|
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
|
|
<B><A HREF="/cgi-bin/man/man2html?3+fseek">fseek</A></B>(3)
|
|
|
|
or
|
|
<B><A HREF="/cgi-bin/man/man2html?3+fseeko">fseeko</A></B>(3).
|
|
|
|
Moving the buffer position past the end
|
|
of the data already written fills the intervening space with
|
|
null characters.
|
|
<P>
|
|
|
|
The
|
|
<B>open_wmemstream</B>()
|
|
|
|
is similar to
|
|
<B>open_memstream</B>(),
|
|
|
|
but operates on wide characters instead of bytes.
|
|
<A NAME="lbAE"> </A>
|
|
<H2>RETURN VALUE</H2>
|
|
|
|
Upon successful completion,
|
|
<B>open_memstream</B>()
|
|
|
|
and
|
|
<B>open_wmemstream</B>()
|
|
|
|
return a
|
|
<I>FILE</I>
|
|
|
|
pointer.
|
|
Otherwise, NULL is returned and
|
|
<I>errno</I>
|
|
|
|
is set to indicate the error.
|
|
<A NAME="lbAF"> </A>
|
|
<H2>VERSIONS</H2>
|
|
|
|
<B>open_memstream</B>()
|
|
|
|
was already available in glibc 1.0.x.
|
|
<B>open_wmemstream</B>()
|
|
|
|
is available since glibc 2.4.
|
|
<A NAME="lbAG"> </A>
|
|
<H2>ATTRIBUTES</H2>
|
|
|
|
For an explanation of the terms used in this section, see
|
|
<B><A HREF="/cgi-bin/man/man2html?7+attributes">attributes</A></B>(7).
|
|
|
|
<TABLE BORDER>
|
|
<TR VALIGN=top><TD><B>Interface</B></TD><TD><B>Attribute</B></TD><TD><B>Value</B><BR></TD></TR>
|
|
<TR VALIGN=top><TD>
|
|
<B>open_memstream</B>(),
|
|
|
|
<BR>
|
|
|
|
<B>open_wmemstream</B>
|
|
|
|
</TD><TD>Thread safety</TD><TD>MT-Safe<BR></TD></TR>
|
|
</TABLE>
|
|
|
|
<P>
|
|
<A NAME="lbAH"> </A>
|
|
<H2>CONFORMING TO</H2>
|
|
|
|
POSIX.1-2008.
|
|
These functions are not specified in POSIX.1-2001,
|
|
and are not widely available on other systems.
|
|
<A NAME="lbAI"> </A>
|
|
<H2>NOTES</H2>
|
|
|
|
There is no file descriptor associated with the file stream
|
|
returned by these functions
|
|
(i.e.,
|
|
<B><A HREF="/cgi-bin/man/man2html?3+fileno">fileno</A></B>(3)
|
|
|
|
will return an error if called on the returned stream).
|
|
<A NAME="lbAJ"> </A>
|
|
<H2>BUGS</H2>
|
|
|
|
In glibc before version 2.7, seeking past the end of a stream created by
|
|
<B>open_memstream</B>()
|
|
|
|
does not enlarge the buffer; instead the
|
|
<B><A HREF="/cgi-bin/man/man2html?3+fseek">fseek</A></B>(3)
|
|
|
|
call fails, returning -1.
|
|
|
|
<A NAME="lbAK"> </A>
|
|
<H2>EXAMPLE</H2>
|
|
|
|
See
|
|
<B><A HREF="/cgi-bin/man/man2html?3+fmemopen">fmemopen</A></B>(3).
|
|
|
|
<A NAME="lbAL"> </A>
|
|
<H2>SEE ALSO</H2>
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+fmemopen">fmemopen</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+fopen">fopen</A></B>(3),
|
|
|
|
<B><A HREF="/cgi-bin/man/man2html?3+setbuf">setbuf</A></B>(3)
|
|
|
|
<A NAME="lbAM"> </A>
|
|
<H2>COLOPHON</H2>
|
|
|
|
This page is part of release 5.05 of the Linux
|
|
<I>man-pages</I>
|
|
|
|
project.
|
|
A description of the project,
|
|
information about reporting bugs,
|
|
and the latest version of this page,
|
|
can be found at
|
|
<A HREF="https://www.kernel.org/doc/man-pages/.">https://www.kernel.org/doc/man-pages/.</A>
|
|
<P>
|
|
|
|
<HR>
|
|
<A NAME="index"> </A><H2>Index</H2>
|
|
<DL>
|
|
<DT id="4"><A HREF="#lbAB">NAME</A><DD>
|
|
<DT id="5"><A HREF="#lbAC">SYNOPSIS</A><DD>
|
|
<DT id="6"><A HREF="#lbAD">DESCRIPTION</A><DD>
|
|
<DT id="7"><A HREF="#lbAE">RETURN VALUE</A><DD>
|
|
<DT id="8"><A HREF="#lbAF">VERSIONS</A><DD>
|
|
<DT id="9"><A HREF="#lbAG">ATTRIBUTES</A><DD>
|
|
<DT id="10"><A HREF="#lbAH">CONFORMING TO</A><DD>
|
|
<DT id="11"><A HREF="#lbAI">NOTES</A><DD>
|
|
<DT id="12"><A HREF="#lbAJ">BUGS</A><DD>
|
|
<DT id="13"><A HREF="#lbAK">EXAMPLE</A><DD>
|
|
<DT id="14"><A HREF="#lbAL">SEE ALSO</A><DD>
|
|
<DT id="15"><A HREF="#lbAM">COLOPHON</A><DD>
|
|
</DL>
|
|
<HR>
|
|
This document was created by
|
|
<A HREF="/cgi-bin/man/man2html">man2html</A>,
|
|
using the manual pages.<BR>
|
|
Time: 00:05:49 GMT, March 31, 2021
|
|
</BODY>
|
|
</HTML>
|