itfrombit / osx_handmade_minimal

Mirror repository of https://github.com/itfrombit/osx_handmade
27 stars 6 forks source link

read and write must check EINTR error case #1

Open mmozeiko opened 9 years ago

mmozeiko commented 9 years ago

It is perfectly legal for read and write function to return error code -1 and set errno to EINTR. These values indicate that you must repeat read and write calls. This can happen in weird cases related to how signals work on POSX platforms (such as OSX and Linux).

That's why, for example, GNU C library on Linux provides TEMP_FAILURE_RETRY helper macro that will do such loop for you. See here: http://www.gnu.org/software/libc/manual/html_node/Interrupted-Primitives.html No idea if there is similar macro on OSX, but you can easily write it yourself - either loop, or macro. Here's an example how it can look like: http://osxr.org/glibc/source/posix/unistd.h?v=glibc-2.15#1125

itfrombit commented 9 years ago

I wasn't sure if this was a potential problem on BSD-derived OS X, but I'll put the check in as it surely can't hurt.