summaryrefslogtreecommitdiffhomepage
path: root/mixlib
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
commit51c6106722d508dc25b5f85ed1a0f08adc494a70 (patch)
tree607fbe9f6046a62f436f5f4a85e2a7b262f6fa25 /mixlib
parente245e7a9c21e3a79eb908e6f7e0c752bdac81e90 (diff)
downloadmdk-51c6106722d508dc25b5f85ed1a0f08adc494a70.tar.gz
mdk-51c6106722d508dc25b5f85ed1a0f08adc494a70.tar.bz2
(mix_stat_dir) new function
Diffstat (limited to 'mixlib')
-rw-r--r--mixlib/mix.c34
-rw-r--r--mixlib/mix.h4
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 */