summaryrefslogtreecommitdiffhomepage
path: root/mixlib/mix.c
diff options
context:
space:
mode:
authorJose Antonio Ortega Ruiz <jao@gnu.org>2001-07-05 23:37:15 +0000
committerJose Antonio Ortega Ruiz <jao@gnu.org>2001-07-05 23:37:15 +0000
commit51b640d12df21cbf76ef3dd556316d461aa4abf3 (patch)
treec4987d0002167a915d5ee13f53655f4b2f486bfb /mixlib/mix.c
parent5071a7a4df62a7fe90ba1e3b4ddf539599668459 (diff)
downloadmdk-51b640d12df21cbf76ef3dd556316d461aa4abf3.tar.gz
mdk-51b640d12df21cbf76ef3dd556316d461aa4abf3.tar.bz2
(mix_stat_dir) new function
Diffstat (limited to 'mixlib/mix.c')
-rw-r--r--mixlib/mix.c34
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;
+}