From e064e67c2b2379f4f449d2459e89c90200a4d2ea Mon Sep 17 00:00:00 2001 From: Danny Al-Gaaf Date: Tue, 7 May 2013 17:25:26 +0200 Subject: [PATCH] common/safe_io.c: reduce scope of some ssize_t variables Signed-off-by: Danny Al-Gaaf --- src/common/safe_io.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/src/common/safe_io.c b/src/common/safe_io.c index a7be648ebf41e..ac99db04ad3ee 100644 --- a/src/common/safe_io.c +++ b/src/common/safe_io.c @@ -21,11 +21,10 @@ ssize_t safe_read(int fd, void *buf, size_t count) { - ssize_t r; size_t cnt = 0; while (cnt < count) { - r = read(fd, buf, count - cnt); + ssize_t r = read(fd, buf, count - cnt); if (r <= 0) { if (r == 0) { // EOF @@ -53,10 +52,8 @@ ssize_t safe_read_exact(int fd, void *buf, size_t count) ssize_t safe_write(int fd, const void *buf, size_t count) { - ssize_t r; - while (count > 0) { - r = write(fd, buf, count); + ssize_t r = write(fd, buf, count); if (r < 0) { if (errno == EINTR) continue; @@ -70,12 +67,11 @@ ssize_t safe_write(int fd, const void *buf, size_t count) ssize_t safe_pread(int fd, void *buf, size_t count, off_t offset) { - ssize_t r; size_t cnt = 0; char *b = (char*)buf; while (cnt < count) { - r = pread(fd, b + cnt, count - cnt, offset + cnt); + ssize_t r = pread(fd, b + cnt, count - cnt, offset + cnt); if (r <= 0) { if (r == 0) { // EOF @@ -103,10 +99,8 @@ ssize_t safe_pread_exact(int fd, void *buf, size_t count, off_t offset) ssize_t safe_pwrite(int fd, const void *buf, size_t count, off_t offset) { - ssize_t r; - while (count > 0) { - r = pwrite(fd, buf, count, offset); + ssize_t r = pwrite(fd, buf, count, offset); if (r < 0) { if (errno == EINTR) continue; -- 2.39.5