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