summaryrefslogtreecommitdiff
path: root/src/shared
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2014-12-12 03:12:58 +0100
committerAnthony G. Basile <blueness@gentoo.org>2014-12-20 08:58:04 -0500
commit12586b6a8a082e712c16c893e9cd727353816f06 (patch)
tree36d1f37250aea09800599e94f6219463d8ac53b6 /src/shared
parentc26b217d918a571104a072eec5068ac8ad94329e (diff)
util: minor simplification for loop_write() and loop_read()
Signed-off-by: Anthony G. Basile <blueness@gentoo.org>
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/util.c24
1 files changed, 14 insertions, 10 deletions
diff --git a/src/shared/util.c b/src/shared/util.c
index b53042182d..633cf437e3 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -809,21 +809,25 @@ ssize_t loop_read(int fd, void *buf, size_t nbytes, bool do_poll) {
ssize_t k;
k = read(fd, p, nbytes);
- if (k < 0 && errno == EINTR)
- continue;
+ if (k < 0) {
+ if (errno == EINTR)
+ continue;
+
+ if (errno == EAGAIN && do_poll) {
- if (k < 0 && errno == EAGAIN && do_poll) {
+ /* We knowingly ignore any return value here,
+ * and expect that any error/EOF is reported
+ * via read() */
- /* We knowingly ignore any return value here,
- * and expect that any error/EOF is reported
- * via read() */
+ fd_wait_for_event(fd, POLLIN, USEC_INFINITY);
+ continue;
+ }
- fd_wait_for_event(fd, POLLIN, USEC_INFINITY);
- continue;
+ return n > 0 ? n : -errno;
}
- if (k <= 0)
- return n > 0 ? n : (k < 0 ? -errno : 0);
+ if (k == 0)
+ return n;
p += k;
nbytes -= k;