summaryrefslogtreecommitdiffstats
path: root/mkdtemp.c
diff options
context:
space:
mode:
authorThomas Wiegner <wiegner@gmx.de>2009-04-25 10:51:03 +0200
committerThomas Wiegner <wiegner@gmx.de>2009-04-25 10:51:03 +0200
commitcf67c6b70b57488d88bceb22c901d806a087f3f3 (patch)
tree7e80542e8d010807fea84f9bfa4d85354e2807e8 /mkdtemp.c
parent96fd7673c2f131dcf3609c502da86bdd39f680db (diff)
Add mkdtemp() from xfce to unbreak gpgme build on Solaris. Closes #3217.
Diffstat (limited to 'mkdtemp.c')
-rw-r--r--mkdtemp.c42
1 files changed, 42 insertions, 0 deletions
diff --git a/mkdtemp.c b/mkdtemp.c
new file mode 100644
index 00000000..0f5edcdd
--- /dev/null
+++ b/mkdtemp.c
@@ -0,0 +1,42 @@
+/* taken from XFCE's Xarchiver, made to work without glib for mutt */
+
+#include <sys/stat.h>
+#include <unistd.h>
+#include <errno.h>
+#include <time.h>
+#include <string.h>
+
+/* mkdtemp fuction for systems which don't have one */
+char *mkdtemp (char *tmpl)
+{
+ static const char LETTERS[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
+ static long value = 0;
+ long v;
+ int len;
+ int i, j;
+
+ len = strlen (tmpl);
+ if (len < 6 || strcmp (&tmpl[len - 6], "XXXXXX") != 0)
+ {
+ errno = EINVAL;
+ return NULL;
+ }
+
+ value += ((long) time (NULL)) ^ getpid ();
+
+ for (i = 0; i < 7 ; ++i, value += 7777)
+ {
+ /* fill in the random bits */
+ for (j = 0, v = value; j < 6; ++j)
+ tmpl[(len - 6) + j] = LETTERS[v % 62]; v /= 62;
+
+ /* try to create the directory */
+ if (mkdir (tmpl, 0700) == 0)
+ return tmpl;
+ else if (errno != EEXIST)
+ return NULL;
+ }
+
+ errno = EEXIST;
+ return NULL;
+}