diff options
Diffstat (limited to 'mixlib')
| -rw-r--r-- | mixlib/mix.c | 34 | ||||
| -rw-r--r-- | mixlib/mix.h | 4 | 
2 files changed, 38 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; +} 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 */ | 
