From ed88bcfb7c15029f9fc95ee2380759a9eb782d46 Mon Sep 17 00:00:00 2001 From: Zbigniew Jędrzejewski-Szmek Date: Wed, 16 Jul 2014 18:59:49 -0400 Subject: 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. --- src/udev/net/link-config.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'src/udev/net') diff --git a/src/udev/net/link-config.c b/src/udev/net/link-config.c index 73243fa107..512885f9c8 100644 --- a/src/udev/net/link-config.c +++ b/src/udev/net/link-config.c @@ -153,11 +153,6 @@ static int load_link(link_config_ctx *ctx, const char *filename) { assert(ctx); assert(filename); - if (null_or_empty_path(filename)) { - log_debug("skipping empty file: %s", filename); - return 0; - } - file = fopen(filename, "re"); if (!file) { if (errno == ENOENT) @@ -166,6 +161,11 @@ static int load_link(link_config_ctx *ctx, const char *filename) { return -errno; } + if (null_or_empty_fd(fileno(file))) { + log_debug("Skipping empty file: %s", filename); + return 0; + } + link = new0(link_config, 1); if (!link) return log_oom(); -- cgit v1.2.3-54-g00ecf