Require that the system mkstemp be able to create
[gnulib.git] / m4 / mkstemp.m4
1 #serial 4
2
3 # On some hosts (e.g., HP-UX 10.20, SunOS 4.1.4, Solaris 2.5.1), mkstemp has a
4 # silly limit that it can create no more than 26 files from a given template.
5 # Other systems lack mkstemp altogether.
6 # On OSF1/Tru64 V4.0F, the system-provided mkstemp function can create
7 # only 32 files per process.
8 # On systems like the above, arrange to use the replacement function.
9 AC_DEFUN([UTILS_FUNC_MKSTEMP],
10 [dnl
11   AC_REPLACE_FUNCS(mkstemp)
12   if test $ac_cv_func_mkstemp = no; then
13     utils_cv_func_mkstemp_limitations=yes
14   else
15     AC_CACHE_CHECK([for mkstemp limitations],
16       utils_cv_func_mkstemp_limitations,
17       [
18         AC_TRY_RUN([
19 #         include <stdlib.h>
20           int main ()
21           {
22             int i;
23             for (i = 0; i < 70; i++)
24               {
25                 char template[] = "conftestXXXXXX";
26                 int fd = mkstemp (template);
27                 if (fd == -1)
28                   exit (1);
29                 close (fd);
30               }
31             exit (0);
32           }
33           ],
34         utils_cv_func_mkstemp_limitations=no,
35         utils_cv_func_mkstemp_limitations=yes,
36         utils_cv_func_mkstemp_limitations=yes
37         )
38       ]
39     )
40   fi
41
42   if test $utils_cv_func_mkstemp_limitations = yes; then
43     AC_LIBOBJ(mkstemp)
44     AC_LIBOBJ(tempname)
45     AC_DEFINE(mkstemp, rpl_mkstemp,
46       [Define to rpl_mkstemp if the replacement function should be used.])
47     gl_PREREQ_MKSTEMP
48     jm_PREREQ_TEMPNAME
49   fi
50 ])
51
52 # Prerequisites of lib/mkstemp.c.
53 AC_DEFUN([gl_PREREQ_MKSTEMP],
54 [
55 ])
56
57 # Prerequisites of lib/tempname.c.
58 AC_DEFUN([jm_PREREQ_TEMPNAME],
59 [
60   AC_REQUIRE([AC_HEADER_STDC])
61   AC_REQUIRE([AC_HEADER_STAT])
62   AC_CHECK_HEADERS_ONCE(fcntl.h sys/time.h unistd.h)
63   AC_CHECK_HEADERS(stdint.h)
64   AC_CHECK_FUNCS(__secure_getenv gettimeofday)
65   AC_CHECK_DECLS_ONCE(getenv)
66   AC_REQUIRE([jm_AC_TYPE_UINTMAX_T])
67 ])