Debian Codegraph @

m4/mkstemp.m4

raw
1 # mkstemp.m4
2 # serial 31
3 dnl Copyright (C) 2001, 2003-2007, 2009-2026 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 some hosts, mkstemp creates files with mode 0666, which is a security
13 # problem and a violation of POSIX 2008.
14 # On systems like the above, arrange to use the replacement function.
15 AC_DEFUN([gl_FUNC_MKSTEMP],
16 [
17 AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
18 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
19
20 AC_CHECK_FUNCS_ONCE([mkstemp])
21 if test $ac_cv_func_mkstemp = yes; then
22 AC_CACHE_CHECK([for working mkstemp],
23 [gl_cv_func_working_mkstemp],
24 [
25 mkdir conftest.mkstemp
26 AC_RUN_IFELSE(
27 [AC_LANG_PROGRAM(
28 [AC_INCLUDES_DEFAULT
29 GL_MDA_DEFINES],
30 [[int result = 0;
31 int i;
32 off_t large = (off_t) 4294967295u;
33 if (large < 0)
34 large = 2147483647;
35 umask (0);
36 for (i = 0; i < 70; i++)
37 {
38 char templ[] = "conftest.mkstemp/coXXXXXX";
39 int (*mkstemp_function) (char *) = mkstemp;
40 int fd = mkstemp_function (templ);
41 if (fd < 0)
42 result |= 1;
43 else
44 {
45 struct stat st;
46 if (lseek (fd, large, SEEK_SET) != large)
47 result |= 2;
48 if (fstat (fd, &st) < 0)
49 result |= 4;
50 else if (st.st_mode & 0077)
51 result |= 8;
52 if (close (fd))
53 result |= 16;
54 }
55 }
56 return result;]])],
57 [gl_cv_func_working_mkstemp=yes],
58 [gl_cv_func_working_mkstemp=no],
59 [case "$host_os" in
60 # Guess yes on glibc systems.
61 *-gnu* | gnu*) gl_cv_func_working_mkstemp="guessing yes" ;;
62 # Guess yes on musl systems.
63 *-musl* | midipix*) gl_cv_func_working_mkstemp="guessing yes" ;;
64 # Guess no on native Windows.
65 mingw* | windows*) gl_cv_func_working_mkstemp="guessing no" ;;
66 # If we don't know, obey --enable-cross-guesses.
67 *) gl_cv_func_working_mkstemp="$gl_cross_guess_normal" ;;
68 esac
69 ])
70 rm -rf conftest.mkstemp
71 ])
72 case "$gl_cv_func_working_mkstemp" in
73 *yes) ;;
74 *)
75 REPLACE_MKSTEMP=1
76 ;;
77 esac
78 else
79 HAVE_MKSTEMP=0
80 fi
81 ])
82
83 # Prerequisites of lib/mkstemp.c.
84 AC_DEFUN([gl_PREREQ_MKSTEMP],
85 [
86 ])