2 # Determine whether getcwd aborts when the length of the working directory
3 # name is unusually large. Any length between 4k and 16k trigger the bug
4 # when using glibc-2.4.90-9 or older.
6 # Copyright (C) 2006, 2009-2011 Free Software Foundation, Inc.
7 # This file is free software; the Free Software Foundation
8 # gives unlimited permission to copy and/or distribute it,
9 # with or without modifications, as long as this notice is preserved.
13 # gl_FUNC_GETCWD_ABORT_BUG([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]])
14 AC_DEFUN([gl_FUNC_GETCWD_ABORT_BUG],
16 AC_CHECK_DECLS_ONCE([getcwd])
17 AC_CHECK_HEADERS_ONCE([unistd.h])
18 AC_REQUIRE([gl_PATHMAX_SNIPPET_PREREQ])
19 AC_CHECK_FUNCS([getpagesize])
20 AC_CACHE_CHECK([whether getcwd aborts when 4k < cwd_length < 16k],
21 gl_cv_func_getcwd_abort_bug,
22 [# Remove any remnants of a previous test.
24 # Arrange for deletion of the temporary directory this test creates.
25 ac_clean_files="$ac_clean_files confdir-14B---"
26 dnl Please keep this in sync with tests/test-getcwd.c.
33 #else /* on Windows with MSVC */
41 /* Don't get link errors because mkdir is redefined to rpl_mkdir. */
48 /* FIXME: skip the run-test altogether on systems without getpagesize. */
49 #if ! HAVE_GETPAGESIZE
50 # define getpagesize() 0
53 /* This size is chosen to be larger than PATH_MAX (4k), yet smaller than
54 the 16kB pagesize on ia64 linux. Those conditions make the code below
55 trigger a bug in glibc's getcwd implementation before 2.4.90-10. */
56 #define TARGET_LEN (5 * 1024)
61 char const *dir_name = "confdir-14B---";
63 size_t initial_cwd_len;
68 /* The bug is triggered when PATH_MAX < getpagesize (), so skip
69 this relatively expensive and invasive test if that's not true. */
70 if (getpagesize () <= PATH_MAX)
73 cwd = getcwd (NULL, 0);
77 initial_cwd_len = strlen (cwd);
79 desired_depth = ((TARGET_LEN - 1 - initial_cwd_len)
80 / (1 + strlen (dir_name)));
81 for (d = 0; d < desired_depth; d++)
83 if (mkdir (dir_name, S_IRWXU) < 0 || chdir (dir_name) < 0)
85 fail = 3; /* Unable to construct deep hierarchy. */
90 /* If libc has the bug in question, this invocation of getcwd
91 results in a failed assertion. */
92 cwd = getcwd (NULL, 0);
94 fail = 4; /* getcwd failed. This is ok, and expected. */
97 /* Call rmdir first, in case the above chdir failed. */
101 if (chdir ("..") < 0)
112 [gl_cv_func_getcwd_abort_bug=no],
113 dnl A "regular" nonzero return does not indicate this bug.
114 dnl An abort will provoke an exit code of something like 134 (128 + 6).
116 && gl_cv_func_getcwd_abort_bug=yes \
117 || gl_cv_func_getcwd_abort_bug=no],
118 [gl_cv_func_getcwd_abort_bug=yes])
120 AS_IF([test $gl_cv_func_getcwd_abort_bug = yes], [$1], [$2])