summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/libudev/util.c36
-rw-r--r--src/libudev/util.h2
2 files changed, 38 insertions, 0 deletions
diff --git a/src/libudev/util.c b/src/libudev/util.c
index cfdf848cce..af7477ba6f 100644
--- a/src/libudev/util.c
+++ b/src/libudev/util.c
@@ -725,6 +725,42 @@ int execute_command(const char *command, char *const argv[])
}
}
+int flush_fd(int fd) {
+ struct pollfd pollfd = {
+ .fd = fd,
+ .events = POLLIN,
+ };
+
+ for (;;) {
+ char buf[LINE_MAX];
+ ssize_t l;
+ int r;
+
+ r = poll(&pollfd, 1, 0);
+ if (r < 0) {
+ if (errno == EINTR)
+ continue;
+
+ return -errno;
+
+ } else if (r == 0)
+ return 0;
+
+ l = read(fd, buf, sizeof(buf));
+ if (l < 0) {
+
+ if (errno == EINTR)
+ continue;
+
+ if (errno == EAGAIN)
+ return 0;
+
+ return -errno;
+ } else if (l == 0)
+ return 0;
+ }
+}
+
int fopen_temporary(const char *path, FILE **_f, char **_temp_path) {
FILE *f;
char *t;
diff --git a/src/libudev/util.h b/src/libudev/util.h
index 332dfb6207..bde7b91e6f 100644
--- a/src/libudev/util.h
+++ b/src/libudev/util.h
@@ -213,6 +213,8 @@ void random_bytes(void *p, size_t n);
int open_terminal(const char *name, int mode);
+int flush_fd(int fd);
+
int fopen_temporary(const char *path, FILE **_f, char **_temp_path);
ssize_t loop_read(int fd, void *buf, size_t nbytes, bool do_poll);