| 1 |
# mkstemp.m4 |
| 2 |
# serial 30 |
| 3 |
dnl Copyright (C) 2001, 2003-2007, 2009-2024 Free Software Foundation, Inc. |
| 4 |
dnl This file is free software; the Free Software Foundation |
| 5 |
dnl gives unlimited permission to copy and/or distribute it, |
| 6 |
dnl with or without modifications, as long as this notice is preserved. |
| 7 |
dnl This file is offered as-is, without any warranty. |
| 8 |
|
| 9 |
# On some hosts (e.g., HP-UX 10.20, SunOS 4.1.4, Solaris 2.5.1), mkstemp has a |
| 10 |
# silly limit that it can create no more than 26 files from a given template. |
| 11 |
# Other systems lack mkstemp altogether. |
| 12 |
# On OSF1/Tru64 V4.0F, the system-provided mkstemp function can create |
| 13 |
# only 32 files per process. |
| 14 |
# On some hosts, mkstemp creates files with mode 0666, which is a security |
| 15 |
# problem and a violation of POSIX 2008. |
| 16 |
# On systems like the above, arrange to use the replacement function. |
| 17 |
AC_DEFUN([gl_FUNC_MKSTEMP], |
| 18 |
[ |
| 19 |
AC_REQUIRE([gl_STDLIB_H_DEFAULTS]) |
| 20 |
AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles |
| 21 |
|
| 22 |
AC_CHECK_FUNCS_ONCE([mkstemp]) |
| 23 |
if test $ac_cv_func_mkstemp = yes; then |
| 24 |
AC_CACHE_CHECK([for working mkstemp], |
| 25 |
[gl_cv_func_working_mkstemp], |
| 26 |
[ |
| 27 |
mkdir conftest.mkstemp |
| 28 |
AC_RUN_IFELSE( |
| 29 |
[AC_LANG_PROGRAM( |
| 30 |
[AC_INCLUDES_DEFAULT |
| 31 |
GL_MDA_DEFINES], |
| 32 |
[[int result = 0; |
| 33 |
int i; |
| 34 |
off_t large = (off_t) 4294967295u; |
| 35 |
if (large < 0) |
| 36 |
large = 2147483647; |
| 37 |
umask (0); |
| 38 |
for (i = 0; i < 70; i++) |
| 39 |
{ |
| 40 |
char templ[] = "conftest.mkstemp/coXXXXXX"; |
| 41 |
int (*mkstemp_function) (char *) = mkstemp; |
| 42 |
int fd = mkstemp_function (templ); |
| 43 |
if (fd < 0) |
| 44 |
result |= 1; |
| 45 |
else |
| 46 |
{ |
| 47 |
struct stat st; |
| 48 |
if (lseek (fd, large, SEEK_SET) != large) |
| 49 |
result |= 2; |
| 50 |
if (fstat (fd, &st) < 0) |
| 51 |
result |= 4; |
| 52 |
else if (st.st_mode & 0077) |
| 53 |
result |= 8; |
| 54 |
if (close (fd)) |
| 55 |
result |= 16; |
| 56 |
} |
| 57 |
} |
| 58 |
return result;]])], |
| 59 |
[gl_cv_func_working_mkstemp=yes], |
| 60 |
[gl_cv_func_working_mkstemp=no], |
| 61 |
[case "$host_os" in |
| 62 |
# Guess yes on glibc systems. |
| 63 |
*-gnu* | gnu*) gl_cv_func_working_mkstemp="guessing yes" ;; |
| 64 |
# Guess yes on musl systems. |
| 65 |
*-musl* | midipix*) gl_cv_func_working_mkstemp="guessing yes" ;; |
| 66 |
# Guess no on native Windows. |
| 67 |
mingw* | windows*) gl_cv_func_working_mkstemp="guessing no" ;; |
| 68 |
# If we don't know, obey --enable-cross-guesses. |
| 69 |
*) gl_cv_func_working_mkstemp="$gl_cross_guess_normal" ;; |
| 70 |
esac |
| 71 |
]) |
| 72 |
rm -rf conftest.mkstemp |
| 73 |
]) |
| 74 |
case "$gl_cv_func_working_mkstemp" in |
| 75 |
*yes) ;; |
| 76 |
*) |
| 77 |
REPLACE_MKSTEMP=1 |
| 78 |
;; |
| 79 |
esac |
| 80 |
else |
| 81 |
HAVE_MKSTEMP=0 |
| 82 |
fi |
| 83 |
]) |
| 84 |
|
| 85 |
# Prerequisites of lib/mkstemp.c. |
| 86 |
AC_DEFUN([gl_PREREQ_MKSTEMP], |
| 87 |
[ |
| 88 |
]) |