diff options
| author | Dana Jansens <danakj@orodu.net> | 2003-10-25 19:13:09 +0000 |
|---|---|---|
| committer | Dana Jansens <danakj@orodu.net> | 2003-10-25 19:13:09 +0000 |
| commit | 5cadc1bff5a26497df28f38e7e9b74d81dfa1084 (patch) | |
| tree | a41dfc5ffc19ac76b3ceaddcfe09cb37074508ec /parser/parse.c | |
| parent | 138d98fc3f743f29bdf78efcdc25b515357d6817 (diff) | |
much improved functions for maknig directories, props to Logan
Diffstat (limited to 'parser/parse.c')
| -rw-r--r-- | parser/parse.c | 47 |
1 files changed, 36 insertions, 11 deletions
diff --git a/parser/parse.c b/parser/parse.c index 69343a8e..f7ca9d70 100644 --- a/parser/parse.c +++ b/parser/parse.c @@ -19,6 +19,7 @@ #include "parse.h" #include <glib.h> #include <string.h> +#include <errno.h> #include <sys/stat.h> #include <sys/types.h> @@ -386,21 +387,45 @@ gchar *parse_expand_tilde(const gchar *f) return ret; } -void parse_mkdir_path(const gchar *path, gint mode) +gboolean parse_mkdir(const gchar *path, gint mode) { - gchar *c, *e; + gboolean ret = TRUE; - g_assert(path[0] == '/'); + g_return_val_if_fail(path != NULL, FALSE); + g_return_val_if_fail(path[0] != '\0', FALSE); - c = g_strdup(path); - e = c; - while ((e = strchr(e + 1, '/'))) { - *e = '\0'; - mkdir(c, mode); - *e = '/'; + if (!g_file_test(path, G_FILE_TEST_IS_DIR)) + if (mkdir(path, mode) == -1) + ret = FALSE; + + return ret; +} + +gboolean parse_mkdir_path(const gchar *path, gint mode) +{ + gboolean ret = TRUE; + + g_return_val_if_fail(path != NULL, FALSE); + g_return_val_if_fail(path[0] == '/', FALSE); + + if (!g_file_test(path, G_FILE_TEST_IS_DIR)) { + gchar *c, *e; + + c = g_strdup(path); + e = c; + while ((e = strchr(e + 1, '/'))) { + *e = '\0'; + if (!(ret = parse_mkdir(c, mode))) + goto parse_mkdir_path_end; + *e = '/'; + } + ret = parse_mkdir(c, mode); + + parse_mkdir_path_end: + g_free(c); } - mkdir(c, mode); - g_free(c); + + return ret; } const gchar* parse_xdg_config_home_path() |
