I am writing a C++ application, which needs to call a library function that expects FILE* opened for read. I have no code of that function - it a black box to me.
The data that I need to pass to the function is in memory in char* buffer of a known size. Ideally, I need to wrap a my buffer in a FILE* structure and pass it in, but I need all the stdio functions that normally works on a FILE* to work on what I pass in, for I don't know which of the functions it calls - definitely fread, possibly fseek too.
The code is rather a performance-sensitive one, so I would like to avoid writing the buffer to disk just so that I could create a FILE* from it by fopen. Is there a way to make a FILE* that would allow from my buffer in memory?
Something like stringstream in c++?
My code needs to be able to run both on windows and linux.
I've seen quite a few questions where people try to write via FILE* to memory. My case is rather a reverse - I need to present the existing buffer as a readable FILE*.
Thanks a lot!
P.S. yes, Using a C string like a FILE* is exactly what I'm asking, somehow I couldn't find it earlier...
Still, if you could suggest a solution on windows, that would be very helpful!