I am writing a straightforward C program on Linux and want to use an existing library API that expects data from a file. I have to give it the file name as const char *. But I have data, as well as the contents of the file already sitting in the buffer allocated on the heap. There is a lot of RAM, and we want high performance. Wanting to avoid writing a temporary file to disk, what is a good way to feed data into this API in a way that looks like a file?
Here is a cheap mock version of my code:
marvelouslibrary.h:
int marvelousfunction(const char *filename);
normal-persons-usage.cpp, for which the library was originally developed:
#include "marvelouslibrary.h"
int somefunction(char *somefilename)
{
return marvelousfunction(somefilename);
}
myprogram.cpp:
#include "marvelouslibrary.h"
int one_of_my_routines()
{
byte* stuff = new byte[1000000];
return marvelousfunction( ??? );
}
, marvelouslibrary API, ; .
mkfifo(), , , . . ? ?
, "B", shuddup . , - , , .