I don't know of any such wrapper, but I don't think it would be too difficult to make your own. That's because C's approach to file I/O hides everything behind the FILE*
interface, which actually makes it nicely object-oriented.
Since you're using C rather than C++, I would suggest using preprocessor macros to replace every instance of fopen()
, fclose()
and fread()
with MEM_fopen()
etc. which are routines that you will define. You will need to define your own FILE
type, for which you could simply use the following:
typedef unsigned char *FILE;
(If you need to manage EOF, you will instead need FILE
to be a struct
with an additional length
field.)
Then your MEM_fread()
function will look something like:
int MEM_fread(unsigned char *buf, size_t size, size_t n, FILE *f) {
memcpy(buf, *f, size * n);
*f += size * n;
return n;
}
The signature for the MEM_fopen()
"constructor" may need to change slightly, since the identifier you need is now a memory address instead of a filename.