shada: Only check errno if read/write returned -1

According to the manual (POSIX) this is the only case when errno is set by these
functions. This is needed because some functions (e.g. buflist_new) leave errno
set to non-zero value under some conditions (e.g. when opening non-existing
files).
This commit is contained in:
ZyX 2015-07-25 13:34:57 +03:00
parent 40bbaa757e
commit fa8e3f3f20

View File

@ -525,7 +525,7 @@ static ptrdiff_t read_file(ShaDaReadDef *const sd_reader, void *const dest,
sd_reader->fpos += (uintmax_t) cur_read_bytes;
assert(read_bytes <= size);
}
if (errno) {
if (cur_read_bytes < 0) {
if (errno == EINTR || errno == EAGAIN) {
errno = 0;
continue;
@ -576,7 +576,7 @@ static ptrdiff_t write_file(ShaDaWriteDef *const sd_writer,
if (cur_written_bytes > 0) {
written_bytes += (size_t) cur_written_bytes;
}
if (errno) {
if (cur_written_bytes < 0) {
if (errno == EINTR || errno == EAGAIN) {
errno = 0;
continue;