For platforms without stdio hooking, the simplest thing we could think
of is to create a temporary file under the hood, then provide gnulib
overrides of fflush and fclose (the only two points at which POSIX
requires that the original arguments to open_memstream are in sync
with what has happened to the stream). Those hooks would then dump
the current contents of the temp file into malloc'd memory. So it is
I/O intensive, but seems feasible to implement. Other alternatives we
considered were using mmap of a temporary file, and doing a gnulib
override of malloc/realloc to recognize the mmap pointer, which is
less I/O intensive but still requires the disk; but that runs into
mmap difficulties (and makes mingw porting harder). We also
considered hooking every single function that takes a FILE* to
understand string streams, but that was ruled out as too invasive to
be practical.