[PATCH] wrapper.c: simplify xread() and xwrite()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



do/while is more straightforward than while(1)/if/continue/return.

Signed-off-by: Tony Finch <dot@xxxxxxxx>
---
 wrapper.c |   16 ++++++----------
 1 files changed, 6 insertions(+), 10 deletions(-)

diff --git a/wrapper.c b/wrapper.c
index 9c71b21..f34f492 100644
--- a/wrapper.c
+++ b/wrapper.c
@@ -116,12 +116,10 @@ void *xmmap(void *start, size_t length,
 ssize_t xread(int fd, void *buf, size_t len)
 {
 	ssize_t nr;
-	while (1) {
+	do {
 		nr = read(fd, buf, len);
-		if ((nr < 0) && (errno == EAGAIN || errno == EINTR))
-			continue;
-		return nr;
-	}
+	} while ((nr < 0) && (errno == EAGAIN || errno == EINTR));
+	return nr;
 }
 
 /*
@@ -132,12 +130,10 @@ ssize_t xread(int fd, void *buf, size_t len)
 ssize_t xwrite(int fd, const void *buf, size_t len)
 {
 	ssize_t nr;
-	while (1) {
+	do {
 		nr = write(fd, buf, len);
-		if ((nr < 0) && (errno == EAGAIN || errno == EINTR))
-			continue;
-		return nr;
-	}
+	} while ((nr < 0) && (errno == EAGAIN || errno == EINTR));
+	return nr;
 }
 
 ssize_t read_in_full(int fd, void *buf, size_t count)
-- 
1.6.2.1

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]