1
0
forked from bip/bip

Merge branch 'path_test_use_stat'

This commit is contained in:
Pierre-Louis Bonicoli 2018-03-22 02:37:38 +01:00
commit eaed46da14
Signed by untrusted user: pilou
GPG Key ID: ADC2651DDACD3538
2 changed files with 7 additions and 5 deletions

View File

@ -30,9 +30,8 @@ char *default_path(const char *biphome, const char *filename, const char *desc)
void assert_path_exists(char *path) void assert_path_exists(char *path)
{ {
FILE* f; struct stat st_buf;
if ((f = fopen(path, "r")) == NULL)
fatal("Unable to open file %s for reading", path); if (stat(path, &st_buf) != 0)
else fatal("Path %s doesn't exist (%s)", path, strerror(errno));
fclose(f);
} }

View File

@ -11,6 +11,9 @@
#ifndef PATH_UTIL_H #ifndef PATH_UTIL_H
#define PATH_UTIL_H #define PATH_UTIL_H
#include <errno.h>
#include <sys/stat.h>
/* return path of filename located in bip home directory */ /* return path of filename located in bip home directory */
char *default_path(const char *biphome, const char *filename, const char *desc); char *default_path(const char *biphome, const char *filename, const char *desc);
/* exit program if path doesn't exist */ /* exit program if path doesn't exist */