diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2017-05-12 00:49:46 +0000 |
---|---|---|
committer | Laurent Bercot <ska-skaware@skarnet.org> | 2017-05-12 00:49:46 +0000 |
commit | 13a62c4ac5feb8d3bc68346eb987bd04d05e3457 (patch) | |
tree | 29fe013dd065c1e5a4e5dd0b11da734f68886c84 /src/libstddjb/openreadnclose.c | |
parent | fa1c2eda11277a24770d7506aafd5e437c658d33 (diff) | |
download | skalibs-13a62c4ac5feb8d3bc68346eb987bd04d05e3457.tar.xz |
bugfix: error reporting in openreadclose
Diffstat (limited to 'src/libstddjb/openreadnclose.c')
-rw-r--r-- | src/libstddjb/openreadnclose.c | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/src/libstddjb/openreadnclose.c b/src/libstddjb/openreadnclose.c index fcecedc..aa61ece 100644 --- a/src/libstddjb/openreadnclose.c +++ b/src/libstddjb/openreadnclose.c @@ -7,11 +7,16 @@ static ssize_t readnclose (int fd, char *s, size_t n) { - ssize_t r = allread(fd, s, n) ; - int e = errno ; + size_t r = allread(fd, s, n) ; + if (errno) + { + int e = errno ; + fd_close(fd) ; + errno = e ; + return -1 ; + } fd_close(fd) ; - if ((r > 0) && (r < (ssize_t)n)) e = EPIPE ; - errno = e ; + if (r < n) errno = EPIPE ; return r ; } |