Estimated time: 30 minutes
Given a file containing a large array of integers, you have to write a function to edit the element at a given index in the array and another function to retrieve a specific element from this array.
Use only open(2)
, mmap(2)
, munmap(2)
, msync(2)
, fstat(2)
and close(2)
.
Hint : msync(2) is a function that ensures that your modifications done in memory (so in the address returned by mmap) will also be saved in the file. Check the documentation to learn how to use it (pay attention to the flags). Call it before munmap() (or your modifications to the memory may be lost) !