static unsigned int get_random(void);
static void seed_random(void);
+#define MKTEMP_FILE 1
+#define MKTEMP_DIR 2
+
#define TEMPCHARS "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
#define NUM_CHARS (sizeof(TEMPCHARS) - 1)
#define INT_MAX 0x7fffffff
#endif
+#ifndef HAVE_MKSTEMPS
int
mkstemps(char *path, int slen)
+{
+ return(mktemp_internal(path, slen, MKTEMP_FILE));
+}
+#endif /* HAVE_MKSTEMPS */
+
+#ifndef HAVE_MKDTEMP
+char *
+mkdtemp(char *path)
+{
+ if (mktemp_internal(path, 0, MKTEMP_DIR) == -1)
+ return(NULL);
+ return(path);
+}
+#endif /* HAVE_MKDTEMP */
+
+int
+mktemp_internal(char *path, int slen, int mode)
{
char *start, *cp, *ep;
const char *tempchars = TEMPCHARS;
*cp = tempchars[r];
}
- fd = open(path, O_CREAT|O_EXCL|O_RDWR, S_IRUSR|S_IWUSR);
- if (fd != -1 || errno != EEXIST)
- return(fd);
+ switch (mode) {
+ case MKTEMP_FILE:
+ fd = open(path, O_CREAT|O_EXCL|O_RDWR, S_IRUSR|S_IWUSR);
+ if (fd != -1 || errno != EEXIST)
+ return(fd);
+ break;
+ case MKTEMP_DIR:
+ if (mkdir(path, S_IRWXU) == 0)
+ return(0);
+ if (errno != EEXIST)
+ return(-1);
+ break;
+ }
} while (--tries);
errno = EEXIST;
/* Define to 1 if you have the `memrchr' function. */
#undef HAVE_MEMRCHR
+/* Define to 1 if you have the `mkdtemp' function. */
+#undef HAVE_MKDTEMP
+
/* Define to 1 if you have the `mkstemps' function. */
#undef HAVE_MKSTEMPS
fi
done
-for ac_func in mkstemps
+for ac_func in mkstemps mkdtemp
do :
- ac_fn_c_check_func "$LINENO" "mkstemps" "ac_cv_func_mkstemps"
-if test "x$ac_cv_func_mkstemps" = x""yes; then :
+ as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
+ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
+eval as_val=\$$as_ac_var
+ if test "x$as_val" = x""yes; then :
cat >>confdefs.h <<_ACEOF
-#define HAVE_MKSTEMPS 1
+#define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1
_ACEOF
else
done
case " $LIBOBJS " in
- *" mkstemps.$ac_objext "* ) ;;
- *) LIBOBJS="$LIBOBJS mkstemps.$ac_objext"
+ *" mkstemp.$ac_objext "* ) ;;
+ *) LIBOBJS="$LIBOBJS mkstemp.$ac_objext"
;;
esac
[ #include <limits.h>
#include <fcntl.h> ])
])
-AC_CHECK_FUNCS(mkstemps, [], [
+AC_CHECK_FUNCS(mkstemps mkdtemp, [], [
AC_CHECK_FUNCS(random lrand48, [break])
- AC_LIBOBJ(mkstemps)
+ AC_LIBOBJ(mkstemp)
])
AC_CHECK_FUNCS(snprintf vsnprintf asprintf vasprintf, , [NEED_SNPRINTF=1])
if test X"$ac_cv_type_struct_timespec" != X"no"; then
#ifndef HAVE_MEMRCHR
void *memrchr(const void *, int, size_t);
#endif
+#ifndef HAVE_MKDTEMP
+char *mkdtemp(char *);
+#endif
#ifndef HAVE_MKSTEMPS
int mkstemps(char *, int);
#endif