From f65dcaaf18ba1e84c598b5e6e95eb2bc94c40a99 Mon Sep 17 00:00:00 2001 From: Henrik Hautakoski Date: Sun, 21 Nov 2010 13:25:04 +0100 Subject: [PATCH] file.c: moved everything into path.c --- Makefile | 1 - src/archived.c | 3 ++- src/file.c | 15 --------------- src/path.c | 9 +++++++++ src/path.h | 2 ++ src/util.h | 2 -- 6 files changed, 13 insertions(+), 19 deletions(-) delete mode 100644 src/file.c diff --git a/Makefile b/Makefile index 2b9b4df..0caf722 100644 --- a/Makefile +++ b/Makefile @@ -44,7 +44,6 @@ 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/archived.c b/src/archived.c index b1d0a6b..eb31b19 100644 --- a/src/archived.c +++ b/src/archived.c @@ -22,6 +22,7 @@ #include "notify.h" #include "database.h" #include "util.h" +#include "path.h" #include "debug.h" static dictionary *config = NULL; @@ -30,7 +31,7 @@ static int load_config(const char *file) { iniparser_freedict(config); - if (file_exists(file)) { + if (is_file(file)) { config = iniparser_load(file); if (NULL == config) return -1; diff --git a/src/file.c b/src/file.c deleted file mode 100644 index 8c629cb..0000000 --- a/src/file.c +++ /dev/null @@ -1,15 +0,0 @@ - -#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/path.c b/src/path.c index fd43bd1..5052516 100644 --- a/src/path.c +++ b/src/path.c @@ -58,6 +58,15 @@ int is_abspath(const char *path) { return 1; } +int is_file(const char *path) { + + struct stat st; + + if (path && stat(path, &st) >= 0) + return S_ISREG(st.st_mode); + return 0; +} + int is_dir(const char *path) { struct stat st; diff --git a/src/path.h b/src/path.h index 5874e35..9bd443b 100644 --- a/src/path.h +++ b/src/path.h @@ -16,6 +16,8 @@ int is_abspath(const char *path); +int is_file(const char *path); + int is_dir(const char *path); char* path_normalize(const char *base, const char *name, unsigned char dir); diff --git a/src/util.h b/src/util.h index 65572b6..4448b65 100644 --- a/src/util.h +++ b/src/util.h @@ -15,6 +15,4 @@ void die(const char *, ...); void die_errno(const char *); -int file_exists(const char *); - #endif /* __UTIL_H */