2 # Check whether getcwd has the bug that it succeeds for a working directory
3 # longer than PATH_MAX, yet returns a truncated directory name.
4 # If so, arrange to compile the wrapper function.
6 # This is necessary for at least GNU libc on linux-2.4.19 and 2.4.20.
7 # I've heard that this is due to a Linux kernel bug, and that it has
8 # been fixed between 2.4.21-pre3 and 2.4.21-pre4. */
12 AC_DEFUN([GL_FUNC_GETCWD_PATH_MAX],
14 AC_CHECK_DECLS([getcwd])
15 AC_CACHE_CHECK([whether getcwd properly handles paths longer than PATH_MAX],
16 gl_cv_func_getcwd_vs_path_max,
18 # Arrange for deletion of the temporary directory this test creates.
19 ac_clean_files="$ac_clean_files confdir3"
20 AC_RUN_IFELSE([AC_LANG_SOURCE([[
26 #include <sys/types.h>
28 /* Don't get link errors because mkdir is redefined to rpl_mkdir. */
35 /* The extra casts work around common compiler bugs. */
36 #define TYPE_SIGNED(t) (! ((t) 0 < (t) -1))
37 /* The outer cast is needed to work around a bug in Cray C 5.0.3.0.
38 It is necessary at least when t == time_t. */
39 #define TYPE_MINIMUM(t) ((t) (TYPE_SIGNED (t) \
40 ? ~ (t) 0 << (sizeof (t) * CHAR_BIT - 1) : (t) 0))
41 #define TYPE_MAXIMUM(t) ((t) (~ (t) 0 - TYPE_MINIMUM (t)))
44 # define INT_MAX TYPE_MAXIMUM (int)
47 /* The length of this name must be 8. */
48 #define DIR_NAME "confdir3"
54 /* The Hurd doesn't define this, so getcwd can't exhibit the bug --
55 at least not on a local file system. And if we were to start worrying
56 about remote file systems, we'd have to enable the wrapper function
57 all of the time, just to be safe. That's not worth the cost. */
59 #elif INT_MAX - 9 <= PATH_MAX
60 /* The '9', above, comes from strlen (DIR_NAME) + 1. */
61 /* FIXME: Assuming there's a system for which this is true,
62 this should be done in a compile test. */
65 char buf[PATH_MAX + 20];
66 char *cwd = getcwd (buf, PATH_MAX);
74 cwd_len = strlen (cwd);
81 cwd_len += 1 + strlen (DIR_NAME);
82 /* If mkdir or chdir fails, be pessimistic and consider that
84 if (mkdir (DIR_NAME, 0700) < 0 || chdir (DIR_NAME) < 0)
89 if ((c = getcwd (buf, PATH_MAX)) == NULL)
91 /* This allows any failure to indicate there is no bug.
92 FIXME: check errno? */
95 if ((len = strlen (c)) != cwd_len)
105 /* Leaving behind such a deep directory is not polite.
106 So clean up here, right away, even though the driving
107 shell script would also clean up. */
111 /* Unlink first, in case the chdir failed. */
113 for (i = 0; i <= n_chdirs; i++)
115 if (chdir ("..") < 0)
125 [gl_cv_func_getcwd_vs_path_max=yes],
126 [gl_cv_func_getcwd_vs_path_max=no],
127 [gl_cv_func_getcwd_vs_path_max=no])])
129 if test $gl_cv_func_getcwd_vs_path_max = yes; then
131 AC_DEFINE(getcwd, rpl_getcwd,
132 [Define to rpl_getcwd if the wrapper function should be used.])