3 # Copyright (C) 2001, 2003-2007, 2009-2020 Free Software Foundation, Inc.
4 # This file is free software; the Free Software Foundation
5 # gives unlimited permission to copy and/or distribute it,
6 # with or without modifications, as long as this notice is preserved.
8 # On some hosts (e.g., HP-UX 10.20, SunOS 4.1.4, Solaris 2.5.1), mkstemp has a
9 # silly limit that it can create no more than 26 files from a given template.
10 # Other systems lack mkstemp altogether.
11 # On OSF1/Tru64 V4.0F, the system-provided mkstemp function can create
12 # only 32 files per process.
13 # On some hosts, mkstemp creates files with mode 0666, which is a security
14 # problem and a violation of POSIX 2008.
15 # On systems like the above, arrange to use the replacement function.
16 AC_DEFUN([gl_FUNC_MKSTEMP],
18 AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
19 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
21 AC_CHECK_FUNCS_ONCE([mkstemp])
22 if test $ac_cv_func_mkstemp = yes; then
23 AC_CACHE_CHECK([for working mkstemp],
24 [gl_cv_func_working_mkstemp],
26 mkdir conftest.mkstemp
33 off_t large = (off_t) 4294967295u;
37 for (i = 0; i < 70; i++)
39 char templ[] = "conftest.mkstemp/coXXXXXX";
40 int (*mkstemp_function) (char *) = mkstemp;
41 int fd = mkstemp_function (templ);
47 if (lseek (fd, large, SEEK_SET) != large)
49 if (fstat (fd, &st) < 0)
51 else if (st.st_mode & 0077)
58 [gl_cv_func_working_mkstemp=yes],
59 [gl_cv_func_working_mkstemp=no],
61 # Guess yes on glibc systems.
62 *-gnu* | gnu*) gl_cv_func_working_mkstemp="guessing yes" ;;
63 # Guess yes on musl systems.
64 *-musl*) gl_cv_func_working_mkstemp="guessing yes" ;;
65 # Guess no on native Windows.
66 mingw*) gl_cv_func_working_mkstemp="guessing no" ;;
67 # If we don't know, obey --enable-cross-guesses.
68 *) gl_cv_func_working_mkstemp="$gl_cross_guess_normal" ;;
71 rm -rf conftest.mkstemp
73 case "$gl_cv_func_working_mkstemp" in
84 # Prerequisites of lib/mkstemp.c.
85 AC_DEFUN([gl_PREREQ_MKSTEMP],