From b0007fea986520495045a2beeb5dffe107f22afd Mon Sep 17 00:00:00 2001 From: Jens Remus Date: Mon, 8 Apr 2019 13:03:53 +0200 Subject: [PATCH] util_path: Simplify logic and get rid of goto MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jens Remus Reviewed-by: Jan Hoeppner Signed-off-by: Jan Höppner --- libutil/util_path.c | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/libutil/util_path.c b/libutil/util_path.c index 8ec19f61..25ed5931 100644 --- a/libutil/util_path.c +++ b/libutil/util_path.c @@ -150,18 +150,14 @@ bool util_path_is_writable(const char *fmt, ...) */ bool util_path_is_reg_file(const char *fmt, ...) { + bool rc = false; struct stat sb; va_list ap; char *path; - bool rc; UTIL_VASPRINTF(&path, fmt, ap); - if (stat(path, &sb)) { - rc = false; - goto free_str; - } - rc = S_ISREG(sb.st_mode) ? true : false; -free_str: + if (stat(path, &sb) == 0) + rc = S_ISREG(sb.st_mode) ? true : false; free(path); return rc; } @@ -179,18 +175,14 @@ free_str: */ bool util_path_is_dir(const char *fmt, ...) { + bool rc = false; struct stat sb; va_list ap; char *path; - bool rc; UTIL_VASPRINTF(&path, fmt, ap); - if (stat(path, &sb)) { - rc = false; - goto free_str; - } - rc = S_ISDIR(sb.st_mode) ? true : false; -free_str: + if (stat(path, &sb) == 0) + rc = S_ISDIR(sb.st_mode) ? true : false; free(path); return rc; }