New module 'tmpfile'.
[gnulib.git] / m4 / tmpfile.m4
1 # Check whether to use a replacement tmpfile() function.
2
3 # Copyright (C) 2007 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 # Written by Ben Pfaff.
9
10 # The native Windows tmpfile function always tries to put the temporary
11 # file in the root directory.  (This behaviour is even documented in
12 # Microsoft's documentation!)  This often fails for ordinary users who
13 # don't have the permissions to write in the root directory.
14 #
15 # We can't test for tmpfile even at runtime, since our test program
16 # might be running with privileges that allow it to write to the root
17 # directory, even though tmpfile wouldn't work in general.  Instead,
18 # just test for a Windows platform (excluding Cygwin).
19
20 AC_DEFUN([gl_TMPFILE], [
21   AC_CACHE_CHECK([whether tmpfile should be overridden],
22     [gl_cv_func_tmpfile_unusable],
23     [AC_EGREP_CPP([choke me], [
24 #if (defined _WIN32 || defined __WIN32__) && !defined __CYGWIN__
25 choke me
26 #endif
27        ],
28        [gl_cv_func_tmpfile_unusable=yes],
29        [gl_cv_func_tmpfile_unusable=no])])
30   if test $gl_cv_func_tmpfile_unusable = yes; then
31     AC_LIBOBJ(tmpfile)
32     AC_DEFINE(tmpfile, rpl_tmpfile,
33       [Define to rpl_tmpfile if the replacement function should be used.])
34     gl_PREREQ_TMPFILE
35   fi
36 ])
37
38 # Prerequisites of lib/tmpfile.c.
39 AC_DEFUN([gl_PREREQ_TMPFILE], [:])