Memory mapped files in C

I played with memory mapped files in C and wondered if there is a way to replace FILE * from fopen with a transparent memory file.

Example:

FILE * fp = g_fopen(...);

//Program does things to this fp.

fclose();

But instead, is it possible to have FILE * fp = my_fopen (...)

Where my own function will open the file on the mmap disk, it may change the contents and then pass FILE * without the program, seeing anything other than the new my_fopen () and my_fclose ().

Is it possible to do this without having to rewrite the method of performing operations in the program?

+3
source share
3 answers

- " ". : http://developers.sun.com/solaris/articles/lib_interposers.html


Oracle , , , / - Oracle.

, :

+5

IO , VM/buffer . , , ? , ?

+2

. / , , my_fopen

FILE * my_fopen()
{
    FILE * myfp
    myfp = fopen(...);
    mmap(fileno(myfp),...);
    return myfp;
}
0

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


All Articles