diff --git a/Makefile b/Makefile index 233d83c..8786e05 100644 --- a/Makefile +++ b/Makefile @@ -33,6 +33,7 @@ obj += src/path.o obj += src/strbuf.o obj += src/xalloc.o obj += src/die.o +obj += src/file.o obj += src/inotify.o obj += src/event.o diff --git a/src/file.c b/src/file.c new file mode 100644 index 0000000..8c629cb --- /dev/null +++ b/src/file.c @@ -0,0 +1,15 @@ + +#include +#include +#include +#include "util.h" + +int file_exists(const char *path) { + + struct stat st; + + if (stat(path, &st) < 0) + return 0; + + return S_ISREG(st.st_mode); +} diff --git a/src/util.h b/src/util.h index 79c527a..66e0da1 100644 --- a/src/util.h +++ b/src/util.h @@ -11,12 +11,10 @@ #ifndef __COMMON_UTIL_H #define __COMMON_UTIL_H -#include - void die(const char *, ...); void die_errno(const char *); -#define file_exists(s) (access((s), F_OK) == 0) +int file_exists(const char *); #endif /* __COMMOT_UTIL_H */