[pacman-dev] [PATCH 5/6] libalpm: Add mkdtemp for systems that do not have it
Will Miles
wmiles at sgl.com
Fri Feb 27 19:43:27 UTC 2015
Signed-off-by: Will Miles <wmiles at sgl.com>
---
configure.ac | 6 +++---
lib/libalpm/trans.c | 35 +++++++++++++++++++++++++++++++++++
2 files changed, 38 insertions(+), 3 deletions(-)
diff --git a/configure.ac b/configure.ac
index da1953e..0a1ef44 100644
--- a/configure.ac
+++ b/configure.ac
@@ -303,9 +303,9 @@ AC_FUNC_MALLOC
AC_FUNC_MKTIME
AC_FUNC_STRCOLL
AC_CHECK_FUNCS([asprintf dup2 getcwd getmntinfo gettimeofday memmove memset \
- mkdir realpath regcomp rmdir setenv setlocale strcasecmp \
- strchr strcspn strdup strerror strndup strnlen strrchr \
- strsep strstr strtol swprintf tcflush wcwidth uname])
+ mkdir mkdtemp realpath regcomp rmdir setenv setlocale \
+ strcasecmp strchr strcspn strdup strerror strndup strnlen \
+ strrchr strsep strstr strtol swprintf tcflush wcwidth uname])
AC_CHECK_MEMBERS([struct stat.st_blksize],,,[[#include <sys/stat.h>]])
# For the diskspace code
diff --git a/lib/libalpm/trans.c b/lib/libalpm/trans.c
index 6a26e75..b3f6044 100644
--- a/lib/libalpm/trans.c
+++ b/lib/libalpm/trans.c
@@ -41,6 +41,41 @@
#include "alpm.h"
#include "deps.h"
+#ifndef HAVE_MKDTEMP
+/* supply a workaround implementation of mkdtemp as the system does not */
+static char *mkdtemp(char *templateName)
+{
+ static const char letters[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
+ const int length = strlen(templateName);
+ char *XXXXXX = templateName + length - 6;
+
+ if((length < 6) || (strncmp(XXXXXX, "XXXXXX", 6) != 0))
+ return 0;
+
+ for(int i = 0; i < 256; ++i) {
+ int v = rand();
+
+ /* Fill in the random bits. */
+ XXXXXX[0] = letters[v % 62];
+ v /= 62;
+ XXXXXX[1] = letters[v % 62];
+ v /= 62;
+ XXXXXX[2] = letters[v % 62];
+ v /= 62;
+ XXXXXX[3] = letters[v % 62];
+ v /= 62;
+ XXXXXX[4] = letters[v % 62];
+ v /= 62;
+ XXXXXX[5] = letters[v % 62];
+
+ if(mkdir(templateName, 0700) == 0)
+ return templateName;
+ }
+
+ return 0;
+}
+#endif
+
/** \addtogroup alpm_trans Transaction Functions
* @brief Functions to manipulate libalpm transactions
* @{
--
2.3.0
More information about the pacman-dev
mailing list