summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2017-05-12 00:49:46 +0000
committerLaurent Bercot <ska-skaware@skarnet.org>2017-05-12 00:49:46 +0000
commit13a62c4ac5feb8d3bc68346eb987bd04d05e3457 (patch)
tree29fe013dd065c1e5a4e5dd0b11da734f68886c84 /src
parentfa1c2eda11277a24770d7506aafd5e437c658d33 (diff)
downloadskalibs-13a62c4ac5feb8d3bc68346eb987bd04d05e3457.tar.xz
bugfix: error reporting in openreadclose
Diffstat (limited to 'src')
-rw-r--r--src/libstddjb/openreadnclose.c13
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 ;
}