bl/mkdtemp.c
author ali <ali@juiblex.co.uk>
Sun Feb 19 21:08:53 2012 +0000 (2012-02-19)
changeset 31 20c603ca5649
permissions -rw-r--r--
Add testcase for words that shouldn't immediately preceed periods
     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"
     7 
     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 */