X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=parser%2Fparse.c;h=f8aed0b5b0228258eef79b2abf28cf2a48dea939;hb=f3801affc6cbb18a05bed59c2ffa3adf38ffe888;hp=69343a8e4c7c216ede2069b52ddbe0dc5ca1b3e5;hpb=138d98fc3f743f29bdf78efcdc25b515357d6817;p=chaz%2Fopenbox diff --git a/parser/parse.c b/parser/parse.c index 69343a8e..f8aed0b5 100644 --- a/parser/parse.c +++ b/parser/parse.c @@ -19,6 +19,7 @@ #include "parse.h" #include #include +#include #include #include @@ -31,7 +32,7 @@ static GSList *xdg_data_dir_paths; struct Callback { gchar *tag; ParseCallback func; - void *data; + gpointer data; }; struct _ObParseInst { @@ -61,7 +62,7 @@ void parse_shutdown(ObParseInst *i) } void parse_register(ObParseInst *i, const gchar *tag, - ParseCallback func, void *data) + ParseCallback func, gpointer data) { struct Callback *c; @@ -295,27 +296,27 @@ static GSList* split_paths(const gchar *paths) void parse_paths_startup() { - gchar *path; + const gchar *path; if (xdg_start) return; xdg_start = TRUE; - path = getenv("XDG_CONFIG_HOME"); + path = g_getenv("XDG_CONFIG_HOME"); if (path && path[0] != '\0') /* not unset or empty */ xdg_config_home_path = g_build_filename(path, NULL); else xdg_config_home_path = g_build_filename(g_get_home_dir(), ".config", NULL); - path = getenv("XDG_DATA_HOME"); + path = g_getenv("XDG_DATA_HOME"); if (path && path[0] != '\0') /* not unset or empty */ xdg_data_home_path = g_build_filename(path, NULL); else xdg_data_home_path = g_build_filename(g_get_home_dir(), ".local", "share", NULL); - path = getenv("XDG_CONFIG_DIRS"); + path = g_getenv("XDG_CONFIG_DIRS"); if (path && path[0] != '\0') /* not unset or empty */ xdg_config_dir_paths = split_paths(path); else { @@ -332,7 +333,7 @@ void parse_paths_startup() xdg_config_home_path, (GSListFunc) g_slist_prepend); - path = getenv("XDG_DATA_DIRS"); + path = g_getenv("XDG_DATA_DIRS"); if (path && path[0] != '\0') /* not unset or empty */ xdg_data_dir_paths = split_paths(path); else { @@ -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) +{ + gboolean ret = TRUE; + + g_return_val_if_fail(path != NULL, FALSE); + g_return_val_if_fail(path[0] != '\0', FALSE); + + 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) { - gchar *c, *e; + gboolean ret = TRUE; + + g_return_val_if_fail(path != NULL, FALSE); + g_return_val_if_fail(path[0] == '/', FALSE); - g_assert(path[0] == '/'); + 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); - c = g_strdup(path); - e = c; - while ((e = strchr(e + 1, '/'))) { - *e = '\0'; - mkdir(c, mode); - *e = '/'; + parse_mkdir_path_end: + g_free(c); } - mkdir(c, mode); - g_free(c); + + return ret; } const gchar* parse_xdg_config_home_path()