aboutsummaryrefslogtreecommitdiffstats
path: root/e-util
diff options
context:
space:
mode:
Diffstat (limited to 'e-util')
-rw-r--r--e-util/e-util.c35
-rw-r--r--e-util/e-util.h4
2 files changed, 38 insertions, 1 deletions
diff --git a/e-util/e-util.c b/e-util/e-util.c
index dbe0448ee1..0363f3e201 100644
--- a/e-util/e-util.c
+++ b/e-util/e-util.c
@@ -166,6 +166,41 @@ e_write_file(const char *filename, const char *data, int flags)
return 0;
}
+/**
+ * e_mkdir_hier:
+ * @path: a directory path
+ * @mode: a mode, as for mkdir(2)
+ *
+ * This creates the named directory with the given @mode, creating
+ * any necessary intermediate directories (with the same @mode).
+ *
+ * Return value: 0 on success, -1 on error, in which case errno will
+ * be set as for mkdir(2).
+ **/
+int
+e_mkdir_hier(const char *path, mode_t mode)
+{
+ char *copy, *p;
+
+ p = copy = g_strdup (path);
+ do {
+ p = strchr (p + 1, '/');
+ if (p)
+ *p = '\0';
+ if (access (copy, F_OK) == -1) {
+ if (mkdir (copy, mode) == -1) {
+ g_free (copy);
+ return -1;
+ }
+ }
+ if (p)
+ *p = '/';
+ } while (p);
+
+ g_free (copy);
+ return 0;
+}
+
#if 0
char *
e_read_uri(const char *uri)
diff --git a/e-util/e-util.h b/e-util/e-util.h
index 0b252a174a..ef331bf9d5 100644
--- a/e-util/e-util.h
+++ b/e-util/e-util.h
@@ -3,6 +3,7 @@
#include <glib.h>
#include <gtk/gtktypeutils.h>
+#include <sys/types.h>
#define E_MAKE_TYPE(l,str,t,ci,i,parent) \
GtkType l##_get_type(void)\
@@ -40,7 +41,8 @@ void e_free_object_list (GList *list);
void e_free_string_list (GList *list);
char *e_read_file (const char *filename);
-gint e_write_file(const char *filename, const char *data, int flags);
+int e_write_file (const char *filename, const char *data, int flags);
+int e_mkdir_hier (const char *path, mode_t mode);
gchar **e_strsplit (const gchar *string,
const gchar *delimiter,