Can I create FILE * with memory mapping in C / Objective-C on iOS?

I have a library that consumes FILE * and outputs the data to another FILE * .

I want to process both the input to this library and the output from this library in memory without reading / writing to / from a file on disk.

We do this in iOS - so running the library as a standalone application and using stdin / stdout not (as far as I know) a viable option.

+6
source share
2 answers

Since ObjC is a superset of C, all you have to do is #import/#include <stdio.h> to access funopen() which itself contains the functions readfn , writefn , seekfn and closefn . And fwopen, which has an example showing how to write to two streams with this other SO question .

Mac OSX and iOS do not include fmemopen and open_memstream because they are clearly not portable linux functions

Starting with macos 10.13, ios 11.0, tvos 11.0 and watchos 4.0, fmemopen and open_memstream are available in stdio, as well as several other useful standard POSIX.1-2008 functions.

+4
source

Take a look at https://github.com/shyuep/pyhull/tree/master/src/fmemopen , I myself tested it on Mac OSX 10.8.2 and it works fine.

The author claims that he must also work on iOS.

+2
source

Source: https://habr.com/ru/post/913747/


All Articles