about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorJames Booth <boothj5@gmail.com>2013-02-02 22:06:19 +0000
committerJames Booth <boothj5@gmail.com>2013-02-02 22:06:19 +0000
commitd86a77495339c3a1156c19979036d704ddf0cead (patch)
tree4f0c9329b6656f12c3aed35ea82b81d85c0c8c4d
parent9d34c41227cb7567b26872f2a10a8f7a1b01f487 (diff)
downloadprofani-tty-d86a77495339c3a1156c19979036d704ddf0cead.tar.gz
Moved directory creating functions to common.h
Removed duplicate function
-rw-r--r--src/common.c13
-rw-r--r--src/common.h1
-rw-r--r--src/files.c39
3 files changed, 21 insertions, 32 deletions
diff --git a/src/common.c b/src/common.c
index 75b05516..46d03fb8 100644
--- a/src/common.c
+++ b/src/common.c
@@ -79,6 +79,19 @@ create_dir(char *name)
             e = mkdir(name, S_IRWXU);
 }
 
+void
+mkdir_recursive(const char *dir)
+{
+    int i;
+    for (i = 1; i <= strlen(dir); i++) {
+        if (dir[i] == '/' || dir[i] == '\0') {
+            gchar *next_dir = g_strndup(dir, i);
+            create_dir(next_dir);
+            g_free(next_dir);
+        }
+    }
+}
+
 char *
 str_replace(const char *string, const char *substr,
     const char *replacement)
diff --git a/src/common.h b/src/common.h
index 2c5860b6..a4ea7a1a 100644
--- a/src/common.h
+++ b/src/common.h
@@ -67,6 +67,7 @@ typedef enum {
 gchar* p_utf8_substring(const gchar *str, glong start_pos, glong end_pos);
 void p_slist_free_full(GSList *items, GDestroyNotify free_func);
 void create_dir(char *name);
+void mkdir_recursive(const char *dir);
 char * str_replace(const char *string, const char *substr,
     const char *replacement);
 int str_contains(char str[], int size, char ch);
diff --git a/src/files.c b/src/files.c
index 1dac6269..08464b82 100644
--- a/src/files.c
+++ b/src/files.c
@@ -27,13 +27,13 @@
 
 #include <glib.h>
 
+#include "common.h"
+
 static void _files_create_config_directory(void);
 static void _files_create_data_directory(void);
 static void _files_create_chatlog_directory(void);
 static void _files_create_log_directory(void);
 static void _files_create_themes_directory(void);
-static void _create_dir(char *name);
-static void _mkdir_recursive(const char *dir);
 static gchar* _xdg_get_config_home(void);
 static gchar* _xdg_get_data_home(void);
 
@@ -118,7 +118,7 @@ _files_create_config_directory(void)
     gchar *xdg_config = _xdg_get_config_home();
     GString *prof_conf_dir = g_string_new(xdg_config);
     g_string_append(prof_conf_dir, "/profanity");
-    _mkdir_recursive(prof_conf_dir->str);
+    mkdir_recursive(prof_conf_dir->str);
     g_free(xdg_config);
     g_string_free(prof_conf_dir, TRUE);
 }
@@ -129,7 +129,7 @@ _files_create_data_directory(void)
     gchar *xdg_data = _xdg_get_data_home();
     GString *prof_data_dir = g_string_new(xdg_data);
     g_string_append(prof_data_dir, "/profanity");
-    _mkdir_recursive(prof_data_dir->str);
+    mkdir_recursive(prof_data_dir->str);
     g_free(xdg_data);
     g_string_free(prof_data_dir, TRUE);
 }
@@ -140,7 +140,7 @@ _files_create_chatlog_directory(void)
     gchar *xdg_data = _xdg_get_data_home();
     GString *chatlogs_dir = g_string_new(xdg_data);
     g_string_append(chatlogs_dir, "/profanity/chatlogs");
-    _mkdir_recursive(chatlogs_dir->str);
+    mkdir_recursive(chatlogs_dir->str);
     g_free(xdg_data);
     g_string_free(chatlogs_dir, TRUE);
 }
@@ -151,7 +151,7 @@ _files_create_log_directory(void)
     gchar *xdg_data = _xdg_get_data_home();
     GString *chatlogs_dir = g_string_new(xdg_data);
     g_string_append(chatlogs_dir, "/profanity/logs");
-    _mkdir_recursive(chatlogs_dir->str);
+    mkdir_recursive(chatlogs_dir->str);
     g_free(xdg_data);
     g_string_free(chatlogs_dir, TRUE);
 }
@@ -162,36 +162,11 @@ _files_create_themes_directory(void)
     gchar *xdg_config = _xdg_get_config_home();
     GString *themes_dir = g_string_new(xdg_config);
     g_string_append(themes_dir, "/profanity/themes");
-    _mkdir_recursive(themes_dir->str);
+    mkdir_recursive(themes_dir->str);
     g_free(xdg_config);
     g_string_free(themes_dir, TRUE);
 }
 
-static void
-_create_dir(char *name)
-{
-    int e;
-    struct stat sb;
-
-    e = stat(name, &sb);
-    if (e != 0)
-        if (errno == ENOENT)
-            e = mkdir(name, S_IRWXU);
-}
-
-static void
-_mkdir_recursive(const char *dir)
-{
-    int i;
-    for (i = 1; i <= strlen(dir); i++) {
-        if (dir[i] == '/' || dir[i] == '\0') {
-            gchar *next_dir = g_strndup(dir, i);
-            _create_dir(next_dir);
-            g_free(next_dir);
-        }
-    }
-}
-
 static gchar *
 _xdg_get_config_home(void)
 {