annotate m4/tmpfile.m4 @ 40160:5c7e0484c1e9

tmpfile: Add support for Android. * m4/tmpfile.m4 (gl_FUNC_TMPFILE): Add a runtime test whether tmpfile() works. * lib/tmpfile.c (tmpfile): Add an alternative implementation for Android. * modules/tmpfile (Depends-on): Add 'stdbool'. * doc/posix-functions/tmpfile.texi: Mention the Android bug. * modules/argv-iter-tests (Depends-on): Add 'tmpfile'.
author Bruno Haible <bruno@clisp.org>
date Sun, 27 Jan 2019 22:03:14 +0100
parents b06060465f09
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
40160
5c7e0484c1e9 tmpfile: Add support for Android.
Bruno Haible <bruno@clisp.org>
parents: 40057
diff changeset
1 # tmpfile.m4 serial 4
40057
b06060465f09 maint: Run 'make update-copyright'
Paul Eggert <eggert@cs.ucla.edu>
parents: 19595
diff changeset
2 # Copyright (C) 2007, 2009-2019 Free Software Foundation, Inc.
8162
46995f2e94ca New module 'tmpfile'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3 # This file is free software; the Free Software Foundation
46995f2e94ca New module 'tmpfile'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
4 # gives unlimited permission to copy and/or distribute it,
46995f2e94ca New module 'tmpfile'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
5 # with or without modifications, as long as this notice is preserved.
46995f2e94ca New module 'tmpfile'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
6
46995f2e94ca New module 'tmpfile'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
7 # Written by Ben Pfaff.
46995f2e94ca New module 'tmpfile'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
8
13137
fd3c9fa89efe tmpfile: Fix C++ test error on mingw.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
9 # Check whether to use a replacement tmpfile() function.
fd3c9fa89efe tmpfile: Fix C++ test error on mingw.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
10
8162
46995f2e94ca New module 'tmpfile'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
11 # The native Windows tmpfile function always tries to put the temporary
46995f2e94ca New module 'tmpfile'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
12 # file in the root directory. (This behaviour is even documented in
46995f2e94ca New module 'tmpfile'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
13 # Microsoft's documentation!) This often fails for ordinary users who
46995f2e94ca New module 'tmpfile'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
14 # don't have the permissions to write in the root directory.
46995f2e94ca New module 'tmpfile'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
15 #
46995f2e94ca New module 'tmpfile'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
16 # We can't test for tmpfile even at runtime, since our test program
46995f2e94ca New module 'tmpfile'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
17 # might be running with privileges that allow it to write to the root
46995f2e94ca New module 'tmpfile'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
18 # directory, even though tmpfile wouldn't work in general. Instead,
46995f2e94ca New module 'tmpfile'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
19 # just test for a Windows platform (excluding Cygwin).
46995f2e94ca New module 'tmpfile'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
20
40160
5c7e0484c1e9 tmpfile: Add support for Android.
Bruno Haible <bruno@clisp.org>
parents: 40057
diff changeset
21 # On Android 4.3, tmpfile() always returns NULL, even if TMPDIR is set
5c7e0484c1e9 tmpfile: Add support for Android.
Bruno Haible <bruno@clisp.org>
parents: 40057
diff changeset
22 # to a writable directory.
5c7e0484c1e9 tmpfile: Add support for Android.
Bruno Haible <bruno@clisp.org>
parents: 40057
diff changeset
23
13138
0ea8feb1eb60 Rename gl_TMPFILE.
Bruno Haible <bruno@clisp.org>
parents: 13137
diff changeset
24 AC_DEFUN([gl_FUNC_TMPFILE], [
13137
fd3c9fa89efe tmpfile: Fix C++ test error on mingw.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
25 AC_REQUIRE([gl_STDIO_H_DEFAULTS])
40160
5c7e0484c1e9 tmpfile: Add support for Android.
Bruno Haible <bruno@clisp.org>
parents: 40057
diff changeset
26 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
5c7e0484c1e9 tmpfile: Add support for Android.
Bruno Haible <bruno@clisp.org>
parents: 40057
diff changeset
27 AC_CACHE_CHECK([whether tmpfile works],
5c7e0484c1e9 tmpfile: Add support for Android.
Bruno Haible <bruno@clisp.org>
parents: 40057
diff changeset
28 [gl_cv_func_tmpfile_works],
8162
46995f2e94ca New module 'tmpfile'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
29 [AC_EGREP_CPP([choke me], [
19595
beb2ad957aca Simplify code. Drop support for Borland C++ on Windows.
Bruno Haible <bruno@clisp.org>
parents: 19484
diff changeset
30 #if defined _WIN32 && !defined __CYGWIN__
8162
46995f2e94ca New module 'tmpfile'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
31 choke me
46995f2e94ca New module 'tmpfile'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
32 #endif
46995f2e94ca New module 'tmpfile'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
33 ],
40160
5c7e0484c1e9 tmpfile: Add support for Android.
Bruno Haible <bruno@clisp.org>
parents: 40057
diff changeset
34 [gl_cv_func_tmpfile_works=no],
5c7e0484c1e9 tmpfile: Add support for Android.
Bruno Haible <bruno@clisp.org>
parents: 40057
diff changeset
35 [AC_RUN_IFELSE(
5c7e0484c1e9 tmpfile: Add support for Android.
Bruno Haible <bruno@clisp.org>
parents: 40057
diff changeset
36 [AC_LANG_SOURCE([[
5c7e0484c1e9 tmpfile: Add support for Android.
Bruno Haible <bruno@clisp.org>
parents: 40057
diff changeset
37 #include <stdio.h>
5c7e0484c1e9 tmpfile: Add support for Android.
Bruno Haible <bruno@clisp.org>
parents: 40057
diff changeset
38 #include <stdlib.h>
5c7e0484c1e9 tmpfile: Add support for Android.
Bruno Haible <bruno@clisp.org>
parents: 40057
diff changeset
39 int
5c7e0484c1e9 tmpfile: Add support for Android.
Bruno Haible <bruno@clisp.org>
parents: 40057
diff changeset
40 main (void)
5c7e0484c1e9 tmpfile: Add support for Android.
Bruno Haible <bruno@clisp.org>
parents: 40057
diff changeset
41 {
5c7e0484c1e9 tmpfile: Add support for Android.
Bruno Haible <bruno@clisp.org>
parents: 40057
diff changeset
42 return tmpfile () == NULL;
5c7e0484c1e9 tmpfile: Add support for Android.
Bruno Haible <bruno@clisp.org>
parents: 40057
diff changeset
43 }]])],
5c7e0484c1e9 tmpfile: Add support for Android.
Bruno Haible <bruno@clisp.org>
parents: 40057
diff changeset
44 [gl_cv_func_tmpfile_works=yes],
5c7e0484c1e9 tmpfile: Add support for Android.
Bruno Haible <bruno@clisp.org>
parents: 40057
diff changeset
45 [gl_cv_func_tmpfile_works=no],
5c7e0484c1e9 tmpfile: Add support for Android.
Bruno Haible <bruno@clisp.org>
parents: 40057
diff changeset
46 [case "$host_os" in
5c7e0484c1e9 tmpfile: Add support for Android.
Bruno Haible <bruno@clisp.org>
parents: 40057
diff changeset
47 # Guess no on Android.
5c7e0484c1e9 tmpfile: Add support for Android.
Bruno Haible <bruno@clisp.org>
parents: 40057
diff changeset
48 linux*-android*) gl_cv_func_tmpfile_works="guessing no" ;;
5c7e0484c1e9 tmpfile: Add support for Android.
Bruno Haible <bruno@clisp.org>
parents: 40057
diff changeset
49 # Guess yes otherwise.
5c7e0484c1e9 tmpfile: Add support for Android.
Bruno Haible <bruno@clisp.org>
parents: 40057
diff changeset
50 *) gl_cv_func_tmpfile_works="guessing yes" ;;
5c7e0484c1e9 tmpfile: Add support for Android.
Bruno Haible <bruno@clisp.org>
parents: 40057
diff changeset
51 esac
5c7e0484c1e9 tmpfile: Add support for Android.
Bruno Haible <bruno@clisp.org>
parents: 40057
diff changeset
52 ])
5c7e0484c1e9 tmpfile: Add support for Android.
Bruno Haible <bruno@clisp.org>
parents: 40057
diff changeset
53 ])
5c7e0484c1e9 tmpfile: Add support for Android.
Bruno Haible <bruno@clisp.org>
parents: 40057
diff changeset
54 ])
5c7e0484c1e9 tmpfile: Add support for Android.
Bruno Haible <bruno@clisp.org>
parents: 40057
diff changeset
55 case "$gl_cv_func_tmpfile_works" in
5c7e0484c1e9 tmpfile: Add support for Android.
Bruno Haible <bruno@clisp.org>
parents: 40057
diff changeset
56 *yes) ;;
5c7e0484c1e9 tmpfile: Add support for Android.
Bruno Haible <bruno@clisp.org>
parents: 40057
diff changeset
57 *) REPLACE_TMPFILE=1 ;;
5c7e0484c1e9 tmpfile: Add support for Android.
Bruno Haible <bruno@clisp.org>
parents: 40057
diff changeset
58 esac
8162
46995f2e94ca New module 'tmpfile'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
59 ])
46995f2e94ca New module 'tmpfile'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
60
46995f2e94ca New module 'tmpfile'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
61 # Prerequisites of lib/tmpfile.c.
46995f2e94ca New module 'tmpfile'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
62 AC_DEFUN([gl_PREREQ_TMPFILE], [:])