Is it possible to fake a file stream, such as stdin, in C?

c, embedded, file-io

Solution

As commented, you could use the POSIX fmemopen function. You'll need a libc providing it, e.g. musl-libc or possibly glibc. BTW for benchmarking purposes you might install some tiny Linux-like OS on your hardware, e.g. uclinux

Problem

I am working on an embedded system with no filesystem and I need to execute programs that take input data from files specified via command like arguments or directly from stdin. I know it is possible to bake-in the file data with the binary using the method from this answer: C/C++ with GCC: Statically add resource files to executable/library but currently I would need to rewrite all the programs to access the data in a new way. Is it possible to bake-in a text file, for example, and access it using a fake file pointer to stdin when running the program?

Original source

Related problems