author | ali <ali@juiblex.co.uk> |
Mon Feb 20 10:10:48 2012 +0000 (2012-02-20) | |
changeset 37 | 037942e1bc4f |
permissions | -rw-r--r-- |
1 #include <stdlib.h>
2 #include <string.h>
3 #include <errno.h>
4 #include <glib.h>
5 #include <glib/gstdio.h>
6 #include "mkdtemp.h"
8 #if !HAVE_G_MKDTEMP
9 char *g_mkdtemp(char *template)
10 {
11 #if !defined(WIN32) && HAVE_MKDTEMP
12 return mkdtemp(template);
13 #else
14 char *s;
15 for(;;)
16 {
17 s=g_strdup(template);
18 mktemp(s);
19 if (!*s)
20 {
21 g_free(s);
22 errno=EEXIST;
23 return NULL;
24 }
25 if (g_mkdir(s,0700)>=0)
26 {
27 strcpy(template,s);
28 g_free(s);
29 return template;
30 }
31 g_free(s);
32 }
33 #endif /* !defined(WIN32) && HAVE_MKDTEMP */
34 }
35 #endif /* !HAVE_G_MKDTEMP */