From ed56e29953fc60756ebfee89423fc72347a41dba Mon Sep 17 00:00:00 2001 From: octo Date: Sat, 10 Jun 2006 12:59:43 +0000 Subject: [PATCH] apcups branch: Fixed the behavior of `sread'. If `sread' receives an EOF it will now close the file descriptor and return an error. Prior to this revision it would try to read again and possibly fail then.. Alternatively it might have crashed, who knows..? ;) --- src/common.c | 9 +++++++++ src/common.h | 3 ++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/common.c b/src/common.c index 98e67044..5487b326 100644 --- a/src/common.c +++ b/src/common.c @@ -144,6 +144,15 @@ ssize_t sread (int fd, void *buf, size_t count) if (status < 0) return (status); + if (status == 0) + { + DBG ("Received EOF from fd %i. " + "Closing fd and returning error.", + fd); + close (fd); + return (-1); + } + assert (nleft >= status); nleft = nleft - status; diff --git a/src/common.h b/src/common.h index f6a8e19a..2be2ff50 100644 --- a/src/common.h +++ b/src/common.h @@ -43,7 +43,8 @@ void *smalloc(size_t size); * * DESCRIPTION * Reads exactly `n' bytes or failes. Syntax and other behavior is analogous - * to `read(2)'. + * to `read(2)'. If EOF is received the file descriptor is closed and an + * error is returned. * * PARAMETERS * `fd' File descriptor to write to. -- 2.30.2