I am facing a problem where the C library exposes only an interface that writes the data to a C FILE structure. This means all the data get saved to disk. I want this library to save the data to memory instead.
Is there a way to emulate FILE structure in my code and make it save the data in memory instead? I imagine FILE has various pointers to functions and I could write my own functions and make them allocate memory and on fwrite write the data to memory.
Can this be done?
Thanks, Boda Cydo.
A portable solution would be to use
fmemopenoropen_memstreamif these functions are available (they’ve been part of GNU libc for a long time and they were added to POSIX in 2008) and simply write to a temporary file then read back into memory if they’re not.