9204fbd1cfb4fed3e15f4046c23670f9d08e20c1
[gnulib.git] / m4 / mkstemp.m4
1 #serial 8
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([gl_FUNC_MKSTEMP],
10 [dnl
11   AC_REPLACE_FUNCS(mkstemp)
12   if test $ac_cv_func_mkstemp = no; then
13     gl_cv_func_mkstemp_limitations=yes
14   else
15     AC_CACHE_CHECK([for mkstemp limitations],
16       gl_cv_func_mkstemp_limitations,
17       [
18         mkdir conftest.mkstemp
19         AC_TRY_RUN([
20 #           include <stdlib.h>
21 #           include <unistd.h>
22             int main ()
23             {
24               int i;
25               for (i = 0; i < 70; i++)
26                 {
27                   char template[] = "conftest.mkstemp/coXXXXXX";
28                   int fd = mkstemp (template);
29                   if (fd == -1)
30                     exit (1);
31                   close (fd);
32                 }
33               exit (0);
34             }
35             ],
36           gl_cv_func_mkstemp_limitations=no,
37           gl_cv_func_mkstemp_limitations=yes,
38           gl_cv_func_mkstemp_limitations=yes
39           )
40         rm -rf conftest.mkstemp
41       ]
42     )
43   fi
44
45   if test $gl_cv_func_mkstemp_limitations = yes; then
46     AC_LIBOBJ(mkstemp)
47     AC_LIBOBJ(tempname)
48     AC_DEFINE(mkstemp, rpl_mkstemp,
49       [Define to rpl_mkstemp if the replacement function should be used.])
50     gl_PREREQ_MKSTEMP
51     gl_PREREQ_TEMPNAME
52   fi
53 ])
54
55 # Prerequisites of lib/mkstemp.c.
56 AC_DEFUN([gl_PREREQ_MKSTEMP],
57 [
58 ])
59
60 # Prerequisites of lib/tempname.c.
61 AC_DEFUN([gl_PREREQ_TEMPNAME],
62 [
63   AC_REQUIRE([AC_HEADER_STAT])
64   AC_CHECK_HEADERS_ONCE(fcntl.h sys/time.h unistd.h)
65   AC_CHECK_HEADERS(stdint.h)
66   AC_CHECK_FUNCS(__secure_getenv gettimeofday)
67   AC_CHECK_DECLS_ONCE(getenv)
68   AC_REQUIRE([gl_AC_TYPE_UINTMAX_T])
69 ])