summaryrefslogtreecommitdiff
path: root/src/libudev
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2014-07-19 13:27:32 -0400
committerAnthony G. Basile <blueness@gentoo.org>2014-07-19 13:27:32 -0400
commite0f01e5b67dfbe41ff810f466e2173390f8d37a7 (patch)
tree29ee85767f0d859e3f91199c747d5896aa3ac71e /src/libudev
parent54fac72da7156f18870ed6a53ea1ccfa80b6a1f6 (diff)
Be more careful when checking for empty files
If we want to avoid reading a totally empty file, it seems better to check after we have opened the file, not before. Signed-off-by: Anthony G. Basile <blueness@gentoo.org>
Diffstat (limited to 'src/libudev')
-rw-r--r--src/libudev/util.c11
-rw-r--r--src/libudev/util.h1
2 files changed, 12 insertions, 0 deletions
diff --git a/src/libudev/util.c b/src/libudev/util.c
index af7477ba6f..116d723a0f 100644
--- a/src/libudev/util.c
+++ b/src/libudev/util.c
@@ -658,6 +658,17 @@ int null_or_empty_path(const char *fn) {
return null_or_empty(&st);
}
+int null_or_empty_fd(int fd) {
+ struct stat st;
+
+ assert(fd >= 0);
+
+ if (fstat(fd, &st) < 0)
+ return -errno;
+
+ return null_or_empty(&st);
+}
+
bool dirent_is_file_with_suffix(const struct dirent *de, const char *suffix) {
assert(de);
diff --git a/src/libudev/util.h b/src/libudev/util.h
index bde7b91e6f..a38e8e61c5 100644
--- a/src/libudev/util.h
+++ b/src/libudev/util.h
@@ -222,6 +222,7 @@ int chmod_and_chown(const char *path, mode_t mode, uid_t uid, gid_t gid);
bool null_or_empty(struct stat *st) _pure_;
int null_or_empty_path(const char *fn);
+int null_or_empty_fd(int fd);
int execute_command(const char *command, char *const argv[]);