diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2014-07-16 18:59:49 -0400 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2014-07-16 19:00:03 -0400 |
commit | ed88bcfb7c15029f9fc95ee2380759a9eb782d46 (patch) | |
tree | 11913b6937d91fa4ee49f312eb044abc38ae7c50 /src/shared/util.c | |
parent | 36f822c4bd077f9121757e24b6516e5c7ada63b5 (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.
Diffstat (limited to 'src/shared/util.c')
-rw-r--r-- | src/shared/util.c | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/shared/util.c b/src/shared/util.c index 75dc58b63d..4fda31c838 100644 --- a/src/shared/util.c +++ b/src/shared/util.c @@ -3604,6 +3604,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); +} + DIR *xopendirat(int fd, const char *name, int flags) { int nfd; DIR *d; |