Import upstream version 1.26
[debian/tar] / m4 / getcwd.m4
1 # getcwd.m4 - check for working getcwd that is compatible with glibc
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 # Written by Paul Eggert.
9 # serial 3
10
11 AC_DEFUN([gl_FUNC_GETCWD_NULL],
12   [
13    AC_CACHE_CHECK([whether getcwd (NULL, 0) allocates memory for result],
14      [gl_cv_func_getcwd_null],
15      [AC_RUN_IFELSE([AC_LANG_PROGRAM([[
16 #        include <unistd.h>
17 #        ifndef getcwd
18          char *getcwd ();
19 #        endif
20 ]], [[
21 #if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
22 /* mingw cwd does not start with '/', but getcwd does allocate.  */
23 #else
24            if (chdir ("/") != 0)
25              return 1;
26            else
27              {
28                char *f = getcwd (NULL, 0);
29                if (! f)
30                  return 2;
31                if (f[0] != '/')
32                  return 3;
33                if (f[1] != '\0')
34                  return 4;
35                return 0;
36              }
37 #endif
38          ]])],
39         [gl_cv_func_getcwd_null=yes],
40         [gl_cv_func_getcwd_null=no],
41         [[
42        case "$host_os" in
43                                # Guess yes on glibc systems.
44          *-gnu*)               gl_cv_func_getcwd_null="guessing yes";;
45                                # Guess yes on Cygwin.
46          cygwin*)              gl_cv_func_getcwd_null="guessing yes";;
47                                # Guess yes on mingw.
48          mingw*)               gl_cv_func_getcwd_null="guessing yes";;
49                                # If we don't know, assume the worst.
50          *)                    gl_cv_func_getcwd_null="guessing no";;
51        esac
52         ]])])
53 ])
54
55 AC_DEFUN([gl_FUNC_GETCWD],
56 [
57   AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
58   AC_REQUIRE([gl_FUNC_GETCWD_NULL])
59   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
60
61   gl_abort_bug=no
62   case $gl_cv_func_getcwd_null,$host_os in
63   *,mingw*)
64     gl_cv_func_getcwd_path_max=yes;;
65   yes,*)
66     gl_FUNC_GETCWD_PATH_MAX
67     gl_FUNC_GETCWD_ABORT_BUG([gl_abort_bug=yes]);;
68   esac
69
70   case $gl_cv_func_getcwd_null,$gl_cv_func_getcwd_path_max,$gl_abort_bug in
71   *yes,yes,no) ;;
72   *)
73     REPLACE_GETCWD=1
74     AC_LIBOBJ([getcwd])
75     gl_PREREQ_GETCWD;;
76   esac
77 ])
78
79 # Prerequisites of lib/getcwd.c.
80 AC_DEFUN([gl_PREREQ_GETCWD],
81 [
82   AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
83   AC_REQUIRE([gl_CHECK_TYPE_STRUCT_DIRENT_D_INO])
84   :
85 ])