checking path: use stat

fopen was used because it's stdlib but stat is already used in other
parts
This commit is contained in:
Pierre-Louis Bonicoli 2018-03-21 11:54:20 +01:00
parent 385be75f7e
commit 3afb16d795
Signed by: pilou
GPG Key ID: ADC2651DDACD3538
2 changed files with 7 additions and 5 deletions

View File

@ -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));
}

View File

@ -11,6 +11,9 @@
#ifndef PATH_UTIL_H
#define PATH_UTIL_H
#include <errno.h>
#include <sys/stat.h>
/* 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 */