]> granicus.if.org Git - mutt/commitdiff
Add mkdtemp() from xfce to unbreak gpgme build on Solaris. Closes #3217.
authorThomas Wiegner <wiegner@gmx.de>
Sat, 25 Apr 2009 08:51:03 +0000 (10:51 +0200)
committerThomas Wiegner <wiegner@gmx.de>
Sat, 25 Apr 2009 08:51:03 +0000 (10:51 +0200)
configure.ac
mkdtemp.c [new file with mode: 0644]
protos.h

index fe479b7a9872cf7b36c3d83c6e3f0dd82626ed99..1aace831fd3847107835077459ae8dab465238f7 100644 (file)
@@ -344,7 +344,7 @@ AC_CHECK_TYPE(ssize_t, int)
 AC_CHECK_FUNCS(fgetpos memmove setegid srand48 strerror)
 
 AC_REPLACE_FUNCS([setenv strcasecmp strdup strsep strtok_r wcscasecmp])
-AC_REPLACE_FUNCS([strcasestr])
+AC_REPLACE_FUNCS([strcasestr mkdtemp])
 
 AC_CHECK_FUNC(getopt)
 if test $ac_cv_func_getopt = yes; then
diff --git a/mkdtemp.c b/mkdtemp.c
new file mode 100644 (file)
index 0000000..0f5edcd
--- /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;
+}
index 6fcc601592464dca11781f0e268f05035607db1a..f35e6d9de298a9656255570a31bfb292a10ef8b3 100644 (file)
--- a/protos.h
+++ b/protos.h
@@ -556,3 +556,7 @@ int wcscasecmp (const wchar_t *a, const wchar_t *b);
 #ifndef HAVE_STRCASESTR
 char *strcasestr (const char *, const char *);
 #endif
+
+#ifndef HAVE_MKDTEMP
+char *mkdtemp (char *tmpl);
+#endif