summaryrefslogtreecommitdiff
path: root/src/basic/io-util.c
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2017-12-12 23:21:09 +0100
committerSven Eden <yamakuzure@gmx.net>2018-05-30 07:49:54 +0200
commitcccf9018aecbbb5f7c31fa9b552622d053f79a45 (patch)
treef4f92d7677a3a64c8b39c531fa674701b89d2855 /src/basic/io-util.c
parentfd11b8eab60cf2fded2c1e4b499526d0ddf3c1fe (diff)
io-util: make flush_fd() return how many bytes where flushed
This is useful so that callers know whether anything at all and how much was flushed. This patches through users of this functions to ensure that the return values > 0 which may be returned now are not propagated in public APIs. Also, users that ignore the return value are changed to do so explicitly now.
Diffstat (limited to 'src/basic/io-util.c')
-rw-r--r--src/basic/io-util.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/basic/io-util.c b/src/basic/io-util.c
index 77c9bdc73..08ad42ed9 100644
--- a/src/basic/io-util.c
+++ b/src/basic/io-util.c
@@ -33,6 +33,7 @@ int flush_fd(int fd) {
.fd = fd,
.events = POLLIN,
};
+ int count = 0;
/* Read from the specified file descriptor, until POLLIN is not set anymore, throwing away everything
* read. Note that some file descriptors (notable IP sockets) will trigger POLLIN even when no data can be read
@@ -52,7 +53,7 @@ int flush_fd(int fd) {
return -errno;
} else if (r == 0)
- return 0;
+ return count;
l = read(fd, buf, sizeof(buf));
if (l < 0) {
@@ -61,11 +62,13 @@ int flush_fd(int fd) {
continue;
if (errno == EAGAIN)
- return 0;
+ return count;
return -errno;
} else if (l == 0)
- return 0;
+ return count;
+
+ count += (int) l;
}
}