I have a library which consumes a FILE *
and outputs data to another FILE *
.
I want to handle both the input to this library and the output from this library in memory without reading/writing to/from a file on the disk.
We're doing this in iOS - so running the library as a separate app and using stdin
/stdout
isn't (as far as I know) a viable option.
Because ObjC is a superset of C, all you have to do is #import/#include <stdio.h>
to gain access to the funopen()
which in itself contains the functions readfn
, writefn
, seekfn
, and closefn
. And fwopen which has an example showing how to write to two streams at this other SO question.
Mac OSX and iOS don't include fmemopen
and open_memstream
because they are apparently unportable linux functions
As of macos 10.13, ios 11.0, tvos 11.0, and watchos 4.0, fmemopen
and open_memstream
along with a few other helpful POSIX.1-2008 standard functions are available in stdio.
Have a look at https://github.com/shyuep/pyhull/tree/master/src/fmemopen, I've tested it myself on a Mac OSX 10.8.2 and it is working ok.
Author states it should also work on iOS.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With