]> git.cworth.org Git - tar/blob - m4/getcwd.m4
upstream: Fix extraction of device nodes.
[tar] / m4 / getcwd.m4
1 # getcwd.m4 - check for working getcwd that is compatible with glibc
2
3 # Copyright (C) 2001, 2003, 2004, 2005, 2006, 2007, 2009, 2010 Free Software
4 # Foundation, Inc.
5 # This file is free software; the Free Software Foundation
6 # gives unlimited permission to copy and/or distribute it,
7 # with or without modifications, as long as this notice is preserved.
8
9 # Written by Paul Eggert.
10 # serial 2
11
12 AC_DEFUN([gl_FUNC_GETCWD_NULL],
13   [
14    AC_CACHE_CHECK([whether getcwd (NULL, 0) allocates memory for result],
15      [gl_cv_func_getcwd_null],
16      [AC_RUN_IFELSE([AC_LANG_PROGRAM([[
17 #        include <unistd.h>
18 #        ifndef getcwd
19          char *getcwd ();
20 #        endif
21 ]], [[
22 #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
23 /* mingw cwd does not start with '/', but getcwd does allocate.  */
24 #else
25            if (chdir ("/") != 0)
26              return 1;
27            else
28              {
29                char *f = getcwd (NULL, 0);
30                return ! (f && f[0] == '/' && !f[1]);
31              }
32 #endif
33          ]])],
34         [gl_cv_func_getcwd_null=yes],
35         [gl_cv_func_getcwd_null=no],
36         [[
37        case "$host_os" in
38                                # Guess yes on glibc systems.
39          *-gnu*)               gl_cv_func_getcwd_null="guessing yes";;
40                                # Guess yes on Cygwin.
41          cygwin*)              gl_cv_func_getcwd_null="guessing yes";;
42                                # Guess yes on mingw.
43          mingw*)               gl_cv_func_getcwd_null="guessing yes";;
44                                # If we don't know, assume the worst.
45          *)                    gl_cv_func_getcwd_null="guessing no";;
46        esac
47         ]])])
48 ])
49
50 AC_DEFUN([gl_FUNC_GETCWD],
51 [
52   AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
53   AC_REQUIRE([gl_FUNC_GETCWD_NULL])
54   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
55
56   gl_abort_bug=no
57   case $gl_cv_func_getcwd_null,$host_os in
58   *,mingw*)
59     gl_cv_func_getcwd_path_max=yes;;
60   yes,*)
61     gl_FUNC_GETCWD_PATH_MAX
62     gl_FUNC_GETCWD_ABORT_BUG([gl_abort_bug=yes]);;
63   esac
64
65   case $gl_cv_func_getcwd_null,$gl_cv_func_getcwd_path_max,$gl_abort_bug in
66   *yes,yes,no) ;;
67   *)
68     REPLACE_GETCWD=1
69     AC_LIBOBJ([getcwd])
70     gl_PREREQ_GETCWD;;
71   esac
72 ])
73
74 # Prerequisites of lib/getcwd.c.
75 AC_DEFUN([gl_PREREQ_GETCWD],
76 [
77   AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
78   AC_REQUIRE([gl_CHECK_TYPE_STRUCT_DIRENT_D_INO])
79   :
80 ])