diff options
author | Dan Winship <danw@src.gnome.org> | 2000-10-08 03:41:42 +0800 |
---|---|---|
committer | Dan Winship <danw@src.gnome.org> | 2000-10-08 03:41:42 +0800 |
commit | 9acde37ac54919dbe9f8d49a1fc7aa914327f3ff (patch) | |
tree | c88c43588af0793739d125ce6d63281f6851b818 /e-util/e-util.c | |
parent | ee625ee5fcc71e9d17fafd53fa17c7cd73558c9f (diff) | |
download | gsoc2013-evolution-9acde37ac54919dbe9f8d49a1fc7aa914327f3ff.tar gsoc2013-evolution-9acde37ac54919dbe9f8d49a1fc7aa914327f3ff.tar.gz gsoc2013-evolution-9acde37ac54919dbe9f8d49a1fc7aa914327f3ff.tar.bz2 gsoc2013-evolution-9acde37ac54919dbe9f8d49a1fc7aa914327f3ff.tar.lz gsoc2013-evolution-9acde37ac54919dbe9f8d49a1fc7aa914327f3ff.tar.xz gsoc2013-evolution-9acde37ac54919dbe9f8d49a1fc7aa914327f3ff.tar.zst gsoc2013-evolution-9acde37ac54919dbe9f8d49a1fc7aa914327f3ff.zip |
New function to make a directory and (if needed), its parents
* gal/util/e-util.c (e_mkdir_hier): New function to make a
directory and (if needed), its parents
svn path=/trunk/; revision=5778
Diffstat (limited to 'e-util/e-util.c')
-rw-r--r-- | e-util/e-util.c | 35 |
1 files changed, 35 insertions, 0 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) |