From 56f3fa373a76842275b199c9ce14fd8e626bd909 Mon Sep 17 00:00:00 2001 From: Tharre Date: Tue, 11 Nov 2014 13:45:14 +0100 Subject: Some refactoring and small fixes. --- src/filepath.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'src/filepath.c') diff --git a/src/filepath.c b/src/filepath.c index d31a008..ff1b476 100644 --- a/src/filepath.c +++ b/src/filepath.c @@ -128,20 +128,26 @@ off_t fsize(const char *fn) { return st.st_size; } -/* Create the directory dir, while removing other 'files' with the same name. */ -void mkdirp(const char *dir) { +/* Create the directory dir, while removing other 'files' with the same name. + Returns true if the directory had to be created or false if it existed */ +// TODO: fix confusing name +bool mkdirp(const char *dir) { struct stat st; if (stat(dir, &st)) { + /* dir doesn't exist or stat failed */ if (errno != ENOENT) fatal(ERRM_STAT, dir); if (mkdir(dir, 0755)) fatal(ERRM_MKDIR, dir); + return 1; } else { if (!S_ISDIR(st.st_mode)) { if (remove(dir)) fatal(ERRM_REMOVE, dir); if (mkdir(dir, 0755)) fatal(ERRM_MKDIR, dir); + return 1; } + return 0; } } -- cgit v1.2.3-70-g09d2