chiark / gitweb /
Be more careful when checking for empty files
[elogind.git] / src / shared / util.c
index 75dc58b63db2edeceab89b3c279a53924a2094de..4fda31c83832de5cd34efd99800e0da0f35dbeaf 100644 (file)
@@ -3604,6 +3604,17 @@ int null_or_empty_path(const char *fn) {
         return null_or_empty(&st);
 }
 
         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);
+}
+
 DIR *xopendirat(int fd, const char *name, int flags) {
         int nfd;
         DIR *d;
 DIR *xopendirat(int fd, const char *name, int flags) {
         int nfd;
         DIR *d;