.\" .\" Copyright (c) 2011 Venkatesh Srinivas, .\" All rights reserved. .\" .\" Redistribution and use in source and binary forms, with or without .\" modification, are permitted provided that the following conditions .\" are met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this list of conditions and the following disclaimer. .\" 2. Redistributions in binary form must reproduce the above copyright .\" notice, this list of conditions and the following disclaimer in the .\" documentation and/or other materials provided with the distribution. .\" .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS .\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED .\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR .\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS .\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR .\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF .\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS .\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN .\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE .\" POSSIBILITY OF SUCH DAMAGE. .\" .Dd September 12, 2011 .Dt OPEN_MEMSTREAM 3 .Os .Sh NAME .Nm open_memstream .Nd open a stream that points to a dynamic buffer .Sh LIBRARY .Lb libc .Sh SYNOPSIS .In stdio.h .Ft FILE * .Fn open_memstream "char **bufp" "size_t *sizep" .Sh DESCRIPTION The .Fn open_memstream function creates a .Vt FILE stream with a dynamically expanding buffer. A pointer to the buffer is stored at the .Fa bufp argument and the length of the data in the buffer is stored at the .Fa sizep argument. The pointer and length values may be updated by writes to the buffer. .Pp Writes append to the buffer and may reallocate it, invalidating the .Fa bufp argument. Writes may fail if the buffer cannot be resized. .Pp The stream is seekable and opened for writing. .Sh RETURN VALUES Upon successful completion, .Fn open_memstream returns a .Vt FILE pointer. Otherwise, .Dv NULL is returned and the global variable .Va errno is set to indicate the error. .Sh ERRORS .Bl -tag -width Er .It Bq Er EINVAL The .Fa bufp argument or the .Fa sizep argument were .Dv NULL . .It Bq Er ENOMEM Memory for the stream buffer or cookie could not be allocated. .El .Sh SEE ALSO .Xr fclose 3 , .Xr fflush 3 , .Xr fmemopen 3 , .Xr fopen 3 .Sh HISTORY The .Fn open_memstream function first appeared in .Dx 2.11 .