From cf67c6b70b57488d88bceb22c901d806a087f3f3 Mon Sep 17 00:00:00 2001 From: Thomas Wiegner Date: Sat, 25 Apr 2009 10:51:03 +0200 Subject: [PATCH] Add mkdtemp() from xfce to unbreak gpgme build on Solaris. Closes #3217. --- configure.ac | 2 +- mkdtemp.c | 42 ++++++++++++++++++++++++++++++++++++++++++ protos.h | 4 ++++ 3 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 mkdtemp.c diff --git a/configure.ac b/configure.ac index fe479b7a..1aace831 100644 --- a/configure.ac +++ b/configure.ac @@ -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 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 +#include +#include +#include +#include + +/* 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; +} diff --git a/protos.h b/protos.h index 6fcc6015..f35e6d9d 100644 --- 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 -- 2.40.0