I have been using similar piece of code since a while.
I I have read some issues regarding treating mapped memory as a string. I am not sure about that though.
So, so I just use strndup(3)
to avoid it anyway.
Its
It's often said to use fopen
, fwrite
and all those f*
functions over read(2)
, write(2)
etc. The reason being, these functions handle the reading and writing quite well by intermediate buffering and are quite well organised too. But in my personal opinion, dealing with files with mmap(2)
generally tends to be faster, gives nice control over the data because of MAP_*
flags and making a structure yourself can organise data pretty well too. These things hold true except in some cases.
Wanted
I wanted some reviews on this code and this way of working with files: