mutt stable branch with some hacks
1/* taken from XFCE's Xarchiver, made to work without glib for mutt */
2
3#include <sys/stat.h>
4#include <unistd.h>
5#include <errno.h>
6#include <time.h>
7#include <string.h>
8
9/* mkdtemp function for systems which don't have one */
10char *mkdtemp (char *tmpl)
11{
12 static const char LETTERS[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
13 static long value = 0;
14 long v;
15 int len;
16 int i, j;
17
18 len = strlen (tmpl);
19 if (len < 6 || strcmp (&tmpl[len - 6], "XXXXXX") != 0)
20 {
21 errno = EINVAL;
22 return NULL;
23 }
24
25 value += ((long) time (NULL)) ^ getpid ();
26
27 for (i = 0; i < 7 ; ++i, value += 7777)
28 {
29 /* fill in the random bits */
30 for (j = 0, v = value; j < 6; ++j)
31 tmpl[(len - 6) + j] = LETTERS[v % 62]; v /= 62;
32
33 /* try to create the directory */
34 if (mkdir (tmpl, 0700) == 0)
35 return tmpl;
36 else if (errno != EEXIST)
37 return NULL;
38 }
39
40 errno = EEXIST;
41 return NULL;
42}