xref: /netbsd/external/gpl2/xcvs/dist/m4/mkstemp.m4 (revision 6550d01e)
1#serial 11
2
3# Copyright (C) 2001, 2003, 2004, 2005 Free Software Foundation, Inc.
4# This file is free software; the Free Software Foundation
5# gives unlimited permission to copy and/or distribute it,
6# with or without modifications, as long as this notice is preserved.
7
8# On some hosts (e.g., HP-UX 10.20, SunOS 4.1.4, Solaris 2.5.1), mkstemp has a
9# silly limit that it can create no more than 26 files from a given template.
10# Other systems lack mkstemp altogether.
11# On OSF1/Tru64 V4.0F, the system-provided mkstemp function can create
12# only 32 files per process.
13# On systems like the above, arrange to use the replacement function.
14AC_DEFUN([gl_FUNC_MKSTEMP],
15[dnl
16  AC_REPLACE_FUNCS(mkstemp)
17  if test $ac_cv_func_mkstemp = no; then
18    gl_cv_func_mkstemp_limitations=yes
19  else
20    AC_CACHE_CHECK([for mkstemp limitations],
21      gl_cv_func_mkstemp_limitations,
22      [
23        mkdir conftest.mkstemp
24	AC_TRY_RUN([
25#           include <stdlib.h>
26#           include <unistd.h>
27	    int main ()
28	    {
29	      int i;
30	      for (i = 0; i < 70; i++)
31		{
32		  char template[] = "conftest.mkstemp/coXXXXXX";
33		  int fd = mkstemp (template);
34		  if (fd == -1)
35		    exit (1);
36		  close (fd);
37		}
38	      exit (0);
39	    }
40	    ],
41	  gl_cv_func_mkstemp_limitations=no,
42	  gl_cv_func_mkstemp_limitations=yes,
43	  gl_cv_func_mkstemp_limitations=yes
44	  )
45        rm -rf conftest.mkstemp
46      ]
47    )
48  fi
49
50  if test $gl_cv_func_mkstemp_limitations = yes; then
51    AC_LIBOBJ(mkstemp)
52    AC_LIBOBJ(tempname)
53    AC_DEFINE(mkstemp, rpl_mkstemp,
54      [Define to rpl_mkstemp if the replacement function should be used.])
55    gl_PREREQ_MKSTEMP
56    gl_PREREQ_TEMPNAME
57  fi
58])
59
60# Prerequisites of lib/mkstemp.c.
61AC_DEFUN([gl_PREREQ_MKSTEMP],
62[
63])
64
65# Prerequisites of lib/tempname.c.
66AC_DEFUN([gl_PREREQ_TEMPNAME],
67[
68  AC_CHECK_HEADERS_ONCE(sys/time.h stdint.h unistd.h)
69  AC_CHECK_FUNCS(__secure_getenv gettimeofday)
70  AC_CHECK_DECLS_ONCE(getenv)
71  AC_REQUIRE([gl_AC_TYPE_UINTMAX_T])
72])
73