From 51c6106722d508dc25b5f85ed1a0f08adc494a70 Mon Sep 17 00:00:00 2001 From: Jose Antonio Ortega Ruiz Date: Thu, 5 Jul 2001 23:37:15 +0000 Subject: (mix_stat_dir) new function --- mixlib/mix.c | 34 ++++++++++++++++++++++++++++++++++ mixlib/mix.h | 4 ++++ 2 files changed, 38 insertions(+) (limited to 'mixlib') 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 +#include +#include +#include + #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; +} diff --git a/mixlib/mix.h b/mixlib/mix.h index 37e7453..2d45636 100644 --- a/mixlib/mix.h +++ b/mixlib/mix.h @@ -60,6 +60,10 @@ mix_release_lib (void); extern const char *MIX_GPL_LICENSE; +/* check dir, and create it if it doesn't exist */ +extern gboolean +mix_stat_dir (const gchar *dirname, const gchar *alias); + #endif /* MIX_H */ -- cgit v1.2.3