fmemopen(3) Library Functions Manual fmemopen(3) fmemopen - (libc -lc) #include FILE *fmemopen(size_t size; void buf[size], size_t size, const char *mode); glibc ( feature_test_macros(7)): fmemopen(): glibc 2.10: _POSIX_C_SOURCE >= 200809L glibc 2.10: _GNU_SOURCE fmemopen() mode. / buf. mode / : r . w . a . r+ . w+ . ( '\0' ). a+ . / . /. fseek(3) ftell(3). . size+1. buf NULL fmemopen() size . . . . ( open_memstream(3)). buf NULL size . (fflush(3)) (fclose(3)) . ( size ) . ('\0') . size . ( ) ( ). size . ( ) stdio. : setbuf(stream, NULL); fmemopen() FILE. NULL errno . attributes(7). +------------+------------------------------------+--------------------+ || | | +------------+------------------------------------+--------------------+ |fmemopen()| | MT-Safe | +------------+------------------------------------+--------------------+ POSIX.1-2008. glibc 1.0.x. POSIX.1-2008. POSIX.1-2008 'b' mode . 1 glibc 'b'. glibc 2.22 ( ) fmemopen() . glibc 2.9 glibc 2.21 glibc fmemopen() "" 'b' mode. fseek(3) SEEK_END ( size) . API : 'b' mode. "wb+" "w+b" . mode fopen(3). glibc 2.22 'b' mode . ( fileno(3) ). glibc 2.22 size fmemopen() EINVAL. glibc 2.22 glibc . glibc 2.22 ("a" "a+") fmemopen() ( ) . glibc 2.22. glibc 2.22 mode fmemopen() ("a" "a+") size buf POSIX.1-2008 . glibc fmemopen() -1. glibc 2.22. glibc 2.22 fseek(3) whence SEEK_END fmemopen() offset . glibc 2.22. glibc 2.9 "" fmemopen() ABI : fmemopen() 'b' mode. fmemopen() open_memstream(3) . ( ) . : $ ./a.out '1 23 43' size=11; ptr=1 529 1849 #define _GNU_SOURCE #include #include #include #include int main(int argc, char *argv[]) { FILE *out, *in; int v, s; size_t size; char *ptr; if (argc != 2) { fprintf(stderr, "Usage: %s '...'\n", argv[0]); exit(EXIT_FAILURE); } in = fmemopen(argv[1], strlen(argv[1]), "r"); if (in == NULL) err(EXIT_FAILURE, "fmemopen"); out = open_memstream(&ptr, &size); if (out == NULL) err(EXIT_FAILURE, "open_memstream"); for (;;) { s = fscanf(in, "%d", &v); if (s <= 0) break; s = fprintf(out, "%d ", v * v); if (s == -1) err(EXIT_FAILURE, "fprintf"); } fclose(in); fclose(out); printf("size=%zu; ptr=%s\n", size, ptr); free(ptr); exit(EXIT_SUCCESS); } fopen(3) fopencookie(3) open_memstream(3) 3 . . : . 6.18 8 2026 fmemopen(3)