aboutsummaryrefslogtreecommitdiffstats
path: root/src/filepath.c
diff options
context:
space:
mode:
authorTharre <tharre3@gmail.com>2014-11-11 13:45:14 +0100
committerTharre <tharre3@gmail.com>2014-11-11 14:03:32 +0100
commit56f3fa373a76842275b199c9ce14fd8e626bd909 (patch)
tree3ef552a3041afe97686532a8bec492e2c786505d /src/filepath.c
parenta07239b0d220fb04dadd6422fd75defa13ee50b9 (diff)
downloadredo-56f3fa373a76842275b199c9ce14fd8e626bd909.tar.gz
redo-56f3fa373a76842275b199c9ce14fd8e626bd909.tar.xz
redo-56f3fa373a76842275b199c9ce14fd8e626bd909.zip
Some refactoring and small fixes.
Diffstat (limited to 'src/filepath.c')
-rw-r--r--src/filepath.c10
1 files changed, 8 insertions, 2 deletions
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;
}
}