1OPEN_MEMSTREAM(3)          Linux Programmer's Manual         OPEN_MEMSTREAM(3)
2
3
4

NAME

6       open_memstream, open_wmemstream -  open a dynamic memory buffer stream
7

SYNOPSIS

9       #include <stdio.h>
10
11       FILE *open_memstream(char **ptr, size_t *sizeloc);
12
13       #include <wchar.h>
14
15       FILE *open_wmemstream(wchar_t **ptr, size_t *sizeloc);
16
17   Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
18
19       open_memstream(), open_wmemstream():
20           Since glibc 2.10:
21               _POSIX_C_SOURCE >= 200809L
22           Before glibc 2.10:
23               _GNU_SOURCE
24

DESCRIPTION

26       The  open_memstream()  function  opens a stream for writing to a memory
27       buffer.  The function dynamically allocates the buffer, and the  buffer
28       automatically  grows  as  needed.   Initially, the buffer has a size of
29       zero.  After closing the stream, the caller should free(3) this buffer.
30
31       The locations pointed to by ptr and sizeloc are used to report, respec‐
32       tively, the current location and the size of the buffer.  The locations
33       referred to by these pointers are  updated  each  time  the  stream  is
34       flushed  (fflush(3))  and when the stream is closed (fclose(3)).  These
35       values remain valid only as long as the caller performs no further out‐
36       put  on  the  stream.   If further output is performed, then the stream
37       must again be flushed before trying to access these values.
38
39       A null byte is maintained at the end of the buffer.  This byte  is  not
40       included in the size value stored at sizeloc.
41
42       The  stream  maintains  the notion of a current position, which is ini‐
43       tially zero (the start of the buffer).  Each write operation implicitly
44       adjusts  the  buffer  position.   The  stream's  buffer position can be
45       explicitly changed with fseek(3) or fseeko(3).  Moving the buffer posi‐
46       tion  past  the  end  of the data already written fills the intervening
47       space with null characters.
48
49       The open_wmemstream() is similar to open_memstream(), but  operates  on
50       wide characters instead of bytes.
51

RETURN VALUE

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

VERSIONS

58       open_memstream()  was  already  available  in  glibc 1.0.x.  open_wmem‐
59       stream() is available since glibc 2.4.
60

ATTRIBUTES

62       For  an  explanation  of  the  terms  used   in   this   section,   see
63       attributes(7).
64
65       ┌──────────────────┬───────────────┬─────────┐
66Interface         Attribute     Value   
67       ├──────────────────┼───────────────┼─────────┤
68open_memstream(), │ Thread safety │ MT-Safe │
69open_wmemstream   │               │         │
70       └──────────────────┴───────────────┴─────────┘
71

CONFORMING TO

73       POSIX.1-2008.   These  functions are not specified in POSIX.1-2001, and
74       are not widely available on other systems.
75

NOTES

77       There is no file descriptor associated with the file stream returned by
78       these  functions (i.e., fileno(3) will return an error if called on the
79       returned stream).
80

BUGS

82       In glibc before version 2.7, seeking past the end of a  stream  created
83       by  open_memstream()  does not enlarge the buffer; instead the fseek(3)
84       call fails, returning -1.
85

EXAMPLE

87       See fmemopen(3).
88

SEE ALSO

90       fmemopen(3), fopen(3), setbuf(3)
91

COLOPHON

93       This page is part of release 5.02 of the Linux  man-pages  project.   A
94       description  of  the project, information about reporting bugs, and the
95       latest    version    of    this    page,    can     be     found     at
96       https://www.kernel.org/doc/man-pages/.
97
98
99
100GNU                               2017-09-15                 OPEN_MEMSTREAM(3)
Impressum