Permalink
Browse files

safe_read() tries to read the number of specified bytes.

It's not a drop-in replacement for read().
It's rather like Ruby's read() and not read_partial().
Rename at least the last argument to make it clear.
  • Loading branch information...
jedisct1 committed Jun 9, 2011
1 parent 4f06de4 commit 8cd798029e639c8dd7845b0ed6fc0b61cd9922de
Showing with 6 additions and 7 deletions.
  1. +5 −6 src/utils.c
  2. +1 −1 src/utils.h
View
@@ -511,28 +511,27 @@ int safe_write(const int fd, const void * const buf_, size_t count,
return 0;
}
-ssize_t safe_read(const int fd, void * const buf_, size_t maxlen)
+ssize_t safe_read(const int fd, void * const buf_, size_t count)
{
unsigned char *buf = (unsigned char *) buf_;
ssize_t readnb;
do {
- while ((readnb = read(fd, buf, maxlen)) < (ssize_t) 0 &&
+ while ((readnb = read(fd, buf, count)) < (ssize_t) 0 &&
errno == EINTR);
- if (readnb < (ssize_t) 0 || readnb > (ssize_t) maxlen) {
+ if (readnb < (ssize_t) 0 || readnb > (ssize_t) count) {
return readnb;
}
if (readnb == (ssize_t) 0) {
ret:
return (ssize_t) (buf - (unsigned char *) buf_);
}
- maxlen -= readnb;
+ count -= readnb;
buf += readnb;
- } while (maxlen > (ssize_t) 0);
+ } while (count > (ssize_t) 0);
goto ret;
}
-
int fcntl_or_flags(const int socket, const int or_flags)
{
int flags;
View
@@ -74,7 +74,7 @@ void untangle_rect(Rectangle2D * const rect);
int safe_write(const int fd, const void * const buf_, size_t count,
const int timeout);
-ssize_t safe_read(const int fd, void * const buf_, size_t maxlen);
+ssize_t safe_read(const int fd, void * const buf_, size_t count);
int fcntl_or_flags(const int socket, const int or_flags);
int fcntl_nand_flags(const int socket, const int nand_flags);

0 comments on commit 8cd7980

Please sign in to comment.