4 ms·
> Let's say it returns a value of 8192 instead, setting errno to EINTR. errno is meaningful only after the function failed. Short write doesn't count as failur
by jwilk 6y ago
> Let's say it returns a value of 8192 instead, setting errno to EINTR.
errno is meaningful only after the function failed. Short write doesn't count as failure.
- jeffbee 6y agoIndeed, errno is not cleared by successful calls, so you can't check it for success. After a short write your only legitimate course of action is to advance the pointer and write again.
- nitrogen 6y agoYou can set errno to 0 and see if it changes.
- jeffbee 6y agoThe syscall is allowed to set it even in case of success.
- deleted 6y ago[deleted]
- rwmj 6y agoThis is sort of right, but the behaviour is a bit subtle. errno should never be set to zero by any POSIX-compliant syscall or library call. However it may be set to something (which is non-zero) on a successful call. Ref: https://pubs.opengroup.org/onlinepubs/9699919799/functions/errno.html https://pubs.opengroup.org/onlinepubs/9699919799/functions/e...
- FreeFull 6y agoI'm not sure there is any guarantee that a function that completes successfully hasn't changed the value of errno anyway.
- nitrogen 6y agoYeah, I didn't mean to imply that you can ignore the return value.
- rachelbythebay 6y agoThat's a derp on my part. Fixed. Thanks. Clearly, this stuff is incredibly complex.
- dependenttypes 6y agonote, while this might be true for write it is not true for fwrite > The fwrite() function shall return the number of elements successfully written, which may be less than nitems if a write error is encountered > if a write error occurs, the error indicator for the stream shall be set, and errno shall be set to indicate the error