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 ex‐
45       plicitly 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() re‐
54       turn 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  at‐
63       tributes(7).
64
65       ┌────────────────────────────────────────────┬───────────────┬─────────┐
66Interface                                   Attribute     Value   
67       ├────────────────────────────────────────────┼───────────────┼─────────┤
68open_memstream(), open_wmemstream()         │ Thread safety │ MT-Safe │
69       └────────────────────────────────────────────┴───────────────┴─────────┘
70

CONFORMING TO

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

NOTES

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

BUGS

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

EXAMPLES

86       See fmemopen(3).
87

SEE ALSO

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

COLOPHON

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