[ChangeLog]
[gnulib.git] / m4 / mkstemp.m4
1 #serial 14
2
3 # Copyright (C) 2001, 2003, 2004, 2005, 2006 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.
14 AC_DEFUN([gl_FUNC_MKSTEMP],
15 [
16   AC_REQUIRE([AC_SYS_LARGEFILE])
17
18   AC_CACHE_CHECK([for working mkstemp],
19     [gl_cv_func_working_mkstemp],
20     [
21       mkdir conftest.mkstemp
22       AC_RUN_IFELSE(
23         [AC_LANG_PROGRAM(
24           [AC_INCLUDES_DEFAULT],
25           [[int i;
26             off_t large = (off_t) 4294967295u;
27             if (large < 0)
28               large = 2147483647;
29             for (i = 0; i < 70; i++)
30               {
31                 char template[] = "conftest.mkstemp/coXXXXXX";
32                 int (*mkstemp_function) (char *) = mkstemp;
33                 int fd = mkstemp_function (template);
34                 if (fd < 0 || lseek (fd, large, SEEK_SET) != large)
35                   return 1;
36                 close (fd);
37               }
38             return 0;]])],
39         [gl_cv_func_working_mkstemp=yes],
40         [gl_cv_func_working_mkstemp=no],
41         [gl_cv_func_working_mkstemp=no])
42       rm -rf conftest.mkstemp
43     ])
44
45   if test $gl_cv_func_working_mkstemp != yes; then
46     AC_DEFINE([__MKSTEMP_PREFIX], [[rpl_]],
47       [Define to rpl_ if the mkstemp replacement function should be used.])
48     AC_LIBOBJ(mkstemp)
49     AC_LIBOBJ(tempname)
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_CHECK_HEADERS_ONCE(sys/time.h)
64   AC_CHECK_FUNCS(__secure_getenv gettimeofday)
65 ])