From d2dc7d84732fc832aaac4891f84d38e3748f1af7 Mon Sep 17 00:00:00 2001 From: Ulrich Drepper Date: Tue, 22 Feb 2005 22:58:32 +0000 Subject: * nscd/nscd-client.h: Include sys/uio.h. (__readall, __readvall, writeall): New prototypes. * nscd/connections.c (writeall): New function. (handle_request): Use it. * nscd/aicache.c (addhstaiX): Likewise. * nscd/initgrcache.c (addinitgroupsX): Likewise. * nscd/hstcache.c (cache_addhst): Likewise. * nscd/grpcache.c (cache_addgr): Likewise. * nscd/pwdcache.c (cache_addpw): Likewise. * nscd/nscd_helper.c (__readall, __readvall): New functions. * nscd/nscd_getai.c (__nscd_getai): Use them. * nscd/nscd_getpw_r.c (__nscd_getpw_r): Likewise. * nscd/nscd_getgr_r.c (__nscd_getgr_r): Likewise. * nscd/nscd_gethst_r.c (__nscd_gethst_r): Likewise. * nscd/nscd_initgroups.c (__nscd_getgrouplist): Likewise. --- nscd/nscd_helper.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) (limited to 'nscd/nscd_helper.c') diff --git a/nscd/nscd_helper.c b/nscd/nscd_helper.c index ea4fb968db..c99cb430aa 100644 --- a/nscd/nscd_helper.c +++ b/nscd/nscd_helper.c @@ -34,6 +34,64 @@ #include "nscd-client.h" +ssize_t +__readall (int fd, void *buf, size_t len) +{ + size_t n = len; + ssize_t ret; + do + { + ret = TEMP_FAILURE_RETRY (__read (fd, buf, n)); + if (ret <= 0) + break; + buf = (char *) buf + ret; + n -= ret; + } + while (n > 0); + return ret < 0 ? ret : len - n; +} + + +ssize_t +__readvall (int fd, const struct iovec *iov, int iovcnt) +{ + ssize_t ret = TEMP_FAILURE_RETRY (__readv (fd, iov, iovcnt)); + if (ret <= 0) + return ret; + + size_t total = 0; + for (int i = 0; i < iovcnt; ++i) + total += iov[i].iov_len; + + if (ret < total) + { + struct iovec iov_buf[iovcnt]; + ssize_t r = ret; + + struct iovec *iovp = memcpy (iov_buf, iov, iovcnt * sizeof (*iov)); + do + { + while (iovp->iov_len <= r) + { + r -= iovp->iov_len; + --iovcnt; + ++iovp; + } + iovp->iov_base = (char *) iovp->iov_base + r; + iovp->iov_len -= r; + r = TEMP_FAILURE_RETRY (__readv (fd, iovp, iovcnt)); + if (r <= 0) + break; + ret += r; + } + while (ret < total); + if (r < 0) + ret = r; + } + return ret; +} + + static int open_socket (void) { -- cgit 1.4.1