c5cd2820d16e8d7677fa084506da6d7e36947e34
[gnulib.git] / m4 / mkstemp.m4
1 #serial 19
2
3 # Copyright (C) 2001, 2003-2007, 2009-2011 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([gl_STDLIB_H_DEFAULTS])
17   AC_REQUIRE([AC_SYS_LARGEFILE])
18
19   AC_CHECK_FUNCS_ONCE([mkstemp])
20   if test $ac_cv_func_mkstemp = yes; then
21     AC_CACHE_CHECK([for working mkstemp],
22       [gl_cv_func_working_mkstemp],
23       [
24         mkdir conftest.mkstemp
25         AC_RUN_IFELSE(
26           [AC_LANG_PROGRAM(
27             [AC_INCLUDES_DEFAULT],
28             [[int result = 0;
29               int i;
30               off_t large = (off_t) 4294967295u;
31               if (large < 0)
32                 large = 2147483647;
33               for (i = 0; i < 70; i++)
34                 {
35                   char templ[] = "conftest.mkstemp/coXXXXXX";
36                   int (*mkstemp_function) (char *) = mkstemp;
37                   int fd = mkstemp_function (templ);
38                   if (fd < 0)
39                     result |= 1;
40                   else
41                     {
42                       if (lseek (fd, large, SEEK_SET) != large)
43                         result |= 2;
44                       close (fd);
45                     }
46                 }
47               return result;]])],
48           [gl_cv_func_working_mkstemp=yes],
49           [gl_cv_func_working_mkstemp=no],
50           [gl_cv_func_working_mkstemp=no])
51         rm -rf conftest.mkstemp
52       ])
53     if test $gl_cv_func_working_mkstemp != yes; then
54       REPLACE_MKSTEMP=1
55       AC_LIBOBJ([mkstemp])
56       gl_PREREQ_MKSTEMP
57     fi
58   else
59     HAVE_MKSTEMP=0
60     AC_LIBOBJ([mkstemp])
61     gl_PREREQ_MKSTEMP
62   fi
63 ])
64
65 # Prerequisites of lib/mkstemp.c.
66 AC_DEFUN([gl_PREREQ_MKSTEMP],
67 [
68 ])