[ACCEPTED]-What should I do when write(fd, buf, count) returns 0?-unix

Accepted answer
Score: 11

Unless you explicitly passed a length of 13 zero to write, this will never happen on a correct, POSIX 12 conformant system. If you want to support 11 all kinds of obscure broken legacy proprietary 10 unices, you'll probably have to investigate 9 what happens on each one, and whether the 8 return value of zero is appearing in place 7 of EINTR or in place of EWOULDBLOCK or some other error...

Personally 6 in 2011 I would just assume it doesn't happen. There 5 are a lot of other things which will break 4 much worse trying to support such old broken 3 junk..

Note, per POSIX:

If write() is interrupted 2 by a signal before it writes any data, it 1 shall return -1 with errno set to [EINTR].

http://pubs.opengroup.org/onlinepubs/9699919799/functions/write.html

Score: 2

The result of the write system call is the 11 total number of bytes written by that system 10 call. In all error cases, it will return 9 -1. Therefore, if the function returns 8 0 we are in an undefined state (based on 7 the generic docs). I would look for any 6 platform specific reason to be returning 5 0 and handle it based on the results of 4 that research. If you turn up no platform 3 specific reason, I'd just exit. You're 2 experiencing undefined behavior from a system 1 call, that can't be good.

Man page: http://linux.die.net/man/2/write

Score: 0

Your question has already been asked and 1 discussed. :) Hope this page helps.

More Related questions