bl/mkdtemp.c
author ali <ali@juiblex.co.uk>
Thu May 30 07:31:24 2013 +0100 (2013-05-30)
changeset 70 aa916da2e452
permissions -rw-r--r--
Switch to using UTF-8 internally
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 */