X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=m4%2Fgetcwd-abort-bug.m4;h=544b03731b7109ffe8413e913091cf0a7da471a3;hb=e7086a9a301ffcfef17edbcba9e7c0312c33f7a8;hp=fd6820dc605a758002d72eb1782345303c49fa33;hpb=c1bb7ba6ba9e685da05f48da5368d9342ba272c1;p=gnulib.git diff --git a/m4/getcwd-abort-bug.m4 b/m4/getcwd-abort-bug.m4 index fd6820dc6..544b03731 100644 --- a/m4/getcwd-abort-bug.m4 +++ b/m4/getcwd-abort-bug.m4 @@ -1,9 +1,9 @@ -# serial 4 +# serial 7 # Determine whether getcwd aborts when the length of the working directory # name is unusually large. Any length between 4k and 16k trigger the bug # when using glibc-2.4.90-9 or older. -# Copyright (C) 2006, 2009-2011 Free Software Foundation, Inc. +# Copyright (C) 2006, 2009-2013 Free Software Foundation, Inc. # This file is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, # with or without modifications, as long as this notice is preserved. @@ -14,6 +14,8 @@ AC_DEFUN([gl_FUNC_GETCWD_ABORT_BUG], [ AC_CHECK_DECLS_ONCE([getcwd]) + AC_CHECK_HEADERS_ONCE([unistd.h]) + AC_REQUIRE([gl_PATHMAX_SNIPPET_PREREQ]) AC_CHECK_FUNCS([getpagesize]) AC_CACHE_CHECK([whether getcwd aborts when 4k < cwd_length < 16k], gl_cv_func_getcwd_abort_bug, @@ -25,12 +27,18 @@ AC_DEFUN([gl_FUNC_GETCWD_ABORT_BUG], AC_RUN_IFELSE( [AC_LANG_SOURCE( [[ +#include #include -#include -#include +#if HAVE_UNISTD_H +# include +#else /* on Windows with MSVC */ +# include +#endif #include #include +]gl_PATHMAX_SNIPPET[ + /* Don't get link errors because mkdir is redefined to rpl_mkdir. */ #undef mkdir @@ -51,16 +59,18 @@ AC_DEFUN([gl_FUNC_GETCWD_ABORT_BUG], int main () { - char const *dir_name = "confdir-14B---"; char *cwd; size_t initial_cwd_len; int fail = 0; - size_t desired_depth; - size_t d; /* The bug is triggered when PATH_MAX < getpagesize (), so skip this relatively expensive and invasive test if that's not true. */ - if (getpagesize () <= PATH_MAX) +#ifdef PATH_MAX + int bug_possible = PATH_MAX < getpagesize (); +#else + int bug_possible = 0; +#endif + if (! bug_possible) return 0; cwd = getcwd (NULL, 0); @@ -69,45 +79,61 @@ main () initial_cwd_len = strlen (cwd); free (cwd); - desired_depth = ((TARGET_LEN - 1 - initial_cwd_len) - / (1 + strlen (dir_name))); - for (d = 0; d < desired_depth; d++) + + if (1) { - if (mkdir (dir_name, S_IRWXU) < 0 || chdir (dir_name) < 0) + static char const dir_name[] = "confdir-14B---"; + size_t desired_depth = ((TARGET_LEN - 1 - initial_cwd_len) + / sizeof dir_name); + size_t d; + for (d = 0; d < desired_depth; d++) { - fail = 3; /* Unable to construct deep hierarchy. */ - break; + if (mkdir (dir_name, S_IRWXU) < 0 || chdir (dir_name) < 0) + { + if (! (errno == ERANGE || errno == ENAMETOOLONG + || errno == ENOENT)) + fail = 3; /* Unable to construct deep hierarchy. */ + break; + } } - } - /* If libc has the bug in question, this invocation of getcwd - results in a failed assertion. */ - cwd = getcwd (NULL, 0); - if (cwd == NULL) - fail = 4; /* getcwd failed. This is ok, and expected. */ - free (cwd); + /* If libc has the bug in question, this invocation of getcwd + results in a failed assertion. */ + cwd = getcwd (NULL, 0); + if (cwd == NULL) + fail = 4; /* getcwd didn't assert, but it failed for a long name + where the answer could have been learned. */ + free (cwd); - /* Call rmdir first, in case the above chdir failed. */ - rmdir (dir_name); - while (0 < d--) - { - if (chdir ("..") < 0) + /* Call rmdir first, in case the above chdir failed. */ + rmdir (dir_name); + while (0 < d--) { - fail = 5; - break; + if (chdir ("..") < 0) + { + fail = 5; + break; + } + rmdir (dir_name); } - rmdir (dir_name); } return fail; } ]])], [gl_cv_func_getcwd_abort_bug=no], - dnl A "regular" nonzero return does not indicate this bug. - dnl An abort will provoke an exit code of something like 134 (128 + 6). - [test $? -gt 128 \ - && gl_cv_func_getcwd_abort_bug=yes \ - || gl_cv_func_getcwd_abort_bug=no], + [dnl An abort will provoke an exit code of something like 134 (128 + 6). + dnl An exit code of 4 can also occur (in OpenBSD 4.9, NetBSD 5.1 for + dnl example): getcwd (NULL, 0) fails rather than returning a string + dnl longer than PATH_MAX. This may be POSIX compliant (in some + dnl interpretations of POSIX). But gnulib's getcwd module wants to + dnl provide a non-NULL value in this case. + ret=$? + if test $ret -ge 128 || test $ret = 4; then + gl_cv_func_getcwd_abort_bug=yes + else + gl_cv_func_getcwd_abort_bug=no + fi], [gl_cv_func_getcwd_abort_bug=yes]) ]) AS_IF([test $gl_cv_func_getcwd_abort_bug = yes], [$1], [$2])