~ubuntu-branches/ubuntu/vivid/gzip/vivid

« back to all changes in this revision

Viewing changes to m4/getcwd.m4

  • Committer: Steve Langasek
  • Date: 2012-06-29 02:07:40 UTC
  • mfrom: (4.1.9 sid)
  • Revision ID: steve.langasek@canonical.com-20120629020740-qqikrblzana08v2y
Merge version 1.5-1.1 from Debian

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# getcwd.m4 - check for working getcwd that is compatible with glibc
2
2
 
3
 
# Copyright (C) 2001, 2003, 2004, 2005, 2006, 2007, 2009, 2010 Free Software
4
 
# Foundation, Inc.
 
3
# Copyright (C) 2001, 2003-2007, 2009-2012 Free Software Foundation, Inc.
5
4
# This file is free software; the Free Software Foundation
6
5
# gives unlimited permission to copy and/or distribute it,
7
6
# with or without modifications, as long as this notice is preserved.
8
7
 
9
8
# Written by Paul Eggert.
10
 
# serial 2
 
9
# serial 12
11
10
 
12
11
AC_DEFUN([gl_FUNC_GETCWD_NULL],
13
12
  [
 
13
   AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
 
14
   AC_CHECK_HEADERS_ONCE([unistd.h])
14
15
   AC_CACHE_CHECK([whether getcwd (NULL, 0) allocates memory for result],
15
16
     [gl_cv_func_getcwd_null],
16
17
     [AC_RUN_IFELSE([AC_LANG_PROGRAM([[
17
 
#        include <unistd.h>
 
18
#        if HAVE_UNISTD_H
 
19
#         include <unistd.h>
 
20
#        else /* on Windows with MSVC */
 
21
#         include <direct.h>
 
22
#        endif
18
23
#        ifndef getcwd
19
24
         char *getcwd ();
20
25
#        endif
21
26
]], [[
22
27
#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
23
 
/* mingw cwd does not start with '/', but getcwd does allocate.  */
 
28
/* mingw cwd does not start with '/', but getcwd does allocate.
 
29
   However, mingw fails to honor non-zero size.  */
24
30
#else
25
31
           if (chdir ("/") != 0)
26
32
             return 1;
27
33
           else
28
34
             {
29
35
               char *f = getcwd (NULL, 0);
30
 
               return ! (f && f[0] == '/' && !f[1]);
 
36
               if (! f)
 
37
                 return 2;
 
38
               if (f[0] != '/')
 
39
                 return 3;
 
40
               if (f[1] != '\0')
 
41
                 return 4;
 
42
               return 0;
31
43
             }
32
44
#endif
33
45
         ]])],
34
46
        [gl_cv_func_getcwd_null=yes],
35
47
        [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
 
48
        [[case "$host_os" in
 
49
                     # Guess yes on glibc systems.
 
50
            *-gnu*)  gl_cv_func_getcwd_null="guessing yes";;
 
51
                     # Guess yes on Cygwin.
 
52
            cygwin*) gl_cv_func_getcwd_null="guessing yes";;
 
53
                     # If we don't know, assume the worst.
 
54
            *)       gl_cv_func_getcwd_null="guessing no";;
 
55
          esac
47
56
        ]])])
48
57
])
49
58
 
 
59
AC_DEFUN([gl_FUNC_GETCWD_SIGNATURE],
 
60
[
 
61
  AC_CACHE_CHECK([for getcwd with POSIX signature],
 
62
    [gl_cv_func_getcwd_posix_signature],
 
63
    [AC_COMPILE_IFELSE(
 
64
      [AC_LANG_PROGRAM(
 
65
         [[#include <unistd.h>]],
 
66
         [[extern
 
67
           #ifdef __cplusplus
 
68
           "C"
 
69
           #endif
 
70
           char *getcwd (char *, size_t);
 
71
         ]])
 
72
      ],
 
73
      [gl_cv_func_getcwd_posix_signature=yes],
 
74
      [gl_cv_func_getcwd_posix_signature=no])
 
75
   ])
 
76
])
 
77
 
 
78
dnl Guarantee that getcwd will malloc with a NULL first argument.  Assumes
 
79
dnl that either the system getcwd is robust, or that calling code is okay
 
80
dnl with spurious failures when run from a directory with an absolute name
 
81
dnl larger than 4k bytes.
 
82
dnl
 
83
dnl Assumes that getcwd exists; if you are worried about obsolete
 
84
dnl platforms that lacked getcwd(), then you need to use the GPL module.
 
85
AC_DEFUN([gl_FUNC_GETCWD_LGPL],
 
86
[
 
87
  AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
 
88
  AC_REQUIRE([gl_FUNC_GETCWD_NULL])
 
89
  AC_REQUIRE([gl_FUNC_GETCWD_SIGNATURE])
 
90
 
 
91
  case $gl_cv_func_getcwd_null,$gl_cv_func_getcwd_posix_signature in
 
92
  *yes,yes) ;;
 
93
  *)
 
94
    dnl Minimal replacement lib/getcwd-lgpl.c.
 
95
    REPLACE_GETCWD=1
 
96
    ;;
 
97
  esac
 
98
])
 
99
 
 
100
dnl Check for all known getcwd bugs; useful for a program likely to be
 
101
dnl executed from an arbitrary location.
50
102
AC_DEFUN([gl_FUNC_GETCWD],
51
103
[
52
104
  AC_REQUIRE([gl_UNISTD_H_DEFAULTS])
53
105
  AC_REQUIRE([gl_FUNC_GETCWD_NULL])
 
106
  AC_REQUIRE([gl_FUNC_GETCWD_SIGNATURE])
54
107
  AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
55
108
 
56
109
  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]);;
 
110
  case "$host_os" in
 
111
    mingw*)
 
112
      gl_cv_func_getcwd_path_max=yes
 
113
      ;;
 
114
    *)
 
115
      gl_FUNC_GETCWD_PATH_MAX
 
116
      case "$gl_cv_func_getcwd_null" in
 
117
        *yes)
 
118
          gl_FUNC_GETCWD_ABORT_BUG([gl_abort_bug=yes])
 
119
          ;;
 
120
      esac
 
121
      ;;
 
122
  esac
 
123
  dnl Define HAVE_MINIMALLY_WORKING_GETCWD and HAVE_PARTLY_WORKING_GETCWD
 
124
  dnl if appropriate.
 
125
  case "$gl_cv_func_getcwd_path_max" in
 
126
    "no, it has the AIX bug") ;;
 
127
    *)
 
128
      AC_DEFINE([HAVE_MINIMALLY_WORKING_GETCWD], [1],
 
129
        [Define to 1 if getcwd minimally works, that is, its result can be
 
130
         trusted when it succeeds.])
 
131
      ;;
 
132
  esac
 
133
  case "$gl_cv_func_getcwd_path_max" in
 
134
    "no, but it is partly working")
 
135
      AC_DEFINE([HAVE_PARTLY_WORKING_GETCWD], [1],
 
136
        [Define to 1 if getcwd works, except it sometimes fails when it
 
137
         shouldn't, setting errno to ERANGE, ENAMETOOLONG, or ENOENT.])
 
138
      ;;
63
139
  esac
64
140
 
65
 
  case $gl_cv_func_getcwd_null,$gl_cv_func_getcwd_path_max,$gl_abort_bug in
66
 
  *yes,yes,no) ;;
67
 
  *)
 
141
  if { case "$gl_cv_func_getcwd_null" in *yes) false;; *) true;; esac; } \
 
142
     || test $gl_cv_func_getcwd_posix_signature != yes \
 
143
     || test "$gl_cv_func_getcwd_path_max" != yes \
 
144
     || test $gl_abort_bug = yes; then
68
145
    REPLACE_GETCWD=1
69
 
    AC_LIBOBJ([getcwd])
70
 
    gl_PREREQ_GETCWD;;
71
 
  esac
 
146
  fi
72
147
])
73
148
 
74
 
# Prerequisites of lib/getcwd.c.
 
149
# Prerequisites of lib/getcwd.c, when full replacement is in effect.
75
150
AC_DEFUN([gl_PREREQ_GETCWD],
76
151
[
77
152
  AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])