From 13a62c4ac5feb8d3bc68346eb987bd04d05e3457 Mon Sep 17 00:00:00 2001 From: Laurent Bercot Date: Fri, 12 May 2017 00:49:46 +0000 Subject: bugfix: error reporting in openreadclose --- src/libstddjb/openreadnclose.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'src') 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 ; } -- cgit v1.2.3