3 ms·
You have exactly the same problem on a read error.
by iforgotpassword 6y ago
You have exactly the same problem on a read error.
- justin66 6y agoNot the problem you described in your second paragraph.
- iforgotpassword 6y agoThen what do you think happens when you read from your mapped memory and the file system is corrupted and returns an error, or the drive has a bad sector, or the nfs server acts up...
- justin66 6y agoReading from a busted file system is a problem to be dealt with (or not), yes, and I certainly wouldn’t recommend mmaping a file shared over nfs if you can help it. I’m not sure what the use case is where that would seem like a good idea. C, pointers, and mmap are dangerous, sharp instruments but I have to wonder who some of these dramatic warnings are for.
- iforgotpassword 6y agoIn general we can probably agree you should always check the return value of read() and write() and handle errors. At least just perror() and abort(), so the user has a chance at finding the problem. Similarly, using mmaped files without handling errors is user hostile since it just crashes the app and SIGBUS gives absolutely no clue to the user what happened. As said, my point is to use mmap when it really makes sense and is worth the hassle, not just because it seems cool and makes the code look a little simpler, exactly because you omit error handling. Especially if you don't know how people will use your software. As you said, mmap on nfs is bad, so you'd basically have to forbid users from using your software with network shares.