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