diff options
Diffstat (limited to 'mixlib/mix.c')
-rw-r--r-- | mixlib/mix.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/mixlib/mix.c b/mixlib/mix.c index 305bb65..34a79b4 100644 --- a/mixlib/mix.c +++ b/mixlib/mix.c @@ -19,6 +19,11 @@ * */ +#include <sys/types.h> +#include <sys/stat.h> +#include <string.h> +#include <errno.h> + #include "mix_types.h" #include "mix_ins.h" @@ -61,3 +66,32 @@ const char *MIX_GPL_LICENSE = "along with this program; if not, write to the Free Software\n" "Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n"; +/* check dir, and create it if it doesn't exist */ +gboolean +mix_stat_dir (const gchar *dirname, const gchar *alias) +{ + struct stat statbuf; + + g_return_val_if_fail (dirname != NULL, FALSE); + if (alias == NULL) alias = ""; + + if (stat (dirname, &statbuf) == -1) + { + if (errno != ENOENT || mkdir (dirname, S_IRWXU | S_IRWXG | S_IRWXO)) + { + g_warning ("Error creating %s dir %s: %s", + alias, dirname, strerror (errno)); + return FALSE; + } + stat (dirname, &statbuf); + } + + if (!(statbuf.st_mode & S_IFDIR)) + { + g_warning ("Error setting %s dir: %s is not a directory", + alias, dirname); + return FALSE; + } + + return TRUE; +} |