From 3afb16d795073d2aff9e2253619757a4e1e6e77c Mon Sep 17 00:00:00 2001 From: Pierre-Louis Bonicoli Date: Wed, 21 Mar 2018 11:54:20 +0100 Subject: [PATCH] checking path: use stat fopen was used because it's stdlib but stat is already used in other parts --- src/path_util.c | 9 ++++----- src/path_util.h | 3 +++ 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/path_util.c b/src/path_util.c index ea3bba1..63617f8 100644 --- a/src/path_util.c +++ b/src/path_util.c @@ -29,9 +29,8 @@ char *default_path(const char *biphome, const char *filename, const char *desc) void assert_path_exists(char *path) { - FILE* f; - if ((f = fopen(path, "r")) == NULL) - fatal("Unable to open file %s for reading", path); - else - fclose(f); + struct stat st_buf; + + if (stat(path, &st_buf) != 0) + fatal("Path %s doesn't exist (%s)", path, strerror(errno)); } diff --git a/src/path_util.h b/src/path_util.h index 87cbf6f..1e663c3 100644 --- a/src/path_util.h +++ b/src/path_util.h @@ -11,6 +11,9 @@ #ifndef PATH_UTIL_H #define PATH_UTIL_H +#include +#include + /* return path of filename located in bip home directory */ char *default_path(const char *biphome, const char *filename, const char *desc); /* exit program if path doesn't exist */