getcwd: tweak comments
[gnulib.git] / 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 4
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 dnl Check for all known getcwd bugs; useful for a program likely to be
56 dnl executed from an arbitrary location.
57 AC_DEFUN([gl_FUNC_GETCWD],
58 [
59   AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
60   AC_REQUIRE([gl_FUNC_GETCWD_NULL])
61   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
62
63   gl_abort_bug=no
64   case $gl_cv_func_getcwd_null,$host_os in
65   *,mingw*)
66     gl_cv_func_getcwd_path_max=yes;;
67   yes,*)
68     gl_FUNC_GETCWD_PATH_MAX
69     gl_FUNC_GETCWD_ABORT_BUG([gl_abort_bug=yes]);;
70   esac
71
72   case $gl_cv_func_getcwd_null,$gl_cv_func_getcwd_path_max,$gl_abort_bug in
73   *yes,yes,no) ;;
74   *)
75     REPLACE_GETCWD=1
76     AC_LIBOBJ([getcwd])
77     gl_PREREQ_GETCWD;;
78   esac
79 ])
80
81 # Prerequisites of lib/getcwd.c.
82 AC_DEFUN([gl_PREREQ_GETCWD],
83 [
84   AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
85   AC_REQUIRE([gl_CHECK_TYPE_STRUCT_DIRENT_D_INO])
86   :
87 ])