From: Bruno Haible Date: Fri, 5 Aug 2011 01:01:01 +0000 (+0200) Subject: pathmax: Leave PATH_MAX undefined on the Hurd, and a constant otherwise. X-Git-Tag: v0.1~2030 X-Git-Url: http://erislabs.net/gitweb/?p=gnulib.git;a=commitdiff_plain;h=6310fc6d3e3f086e825cbd6f53950fbdc1ac7b42 pathmax: Leave PATH_MAX undefined on the Hurd, and a constant otherwise. * lib/pathmax.h (PATH_MAX): Leave it undefined on GNU/Hurd. * lib/chdir-long.h: Include pathmax.h. * lib/clean-temp.c (PATH_MAX): Remove code that is done by pathmax.h. * lib/getcwd.c: Include pathmax.h instead of . (PATH_MAX): Remove code that is done by pathmax.h. * lib/canonicalize.c (PATH_MAX): Provide a fallback value. * lib/tmpfile.c: Add a comment. * m4/pathmax.m4 (gl_PATHMAX): Don't test for pathconf. * modules/chdir-long (Depends-on): Add pathmax. * modules/getcwd (Depends-on): Add pathmax. * tests/test-getcwd.c (test_abort_bug): Avoid syntax error when PATH_MAX is not defined. * doc/posix-headers/limits.texi: Mention the pathmax module. * NEWS: Mention the change. --- diff --git a/ChangeLog b/ChangeLog index fa1c9c5b2..adca1b28c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,21 @@ +2011-08-04 Bruno Haible + + pathmax: Leave PATH_MAX undefined on the Hurd, and a constant otherwise. + * lib/pathmax.h (PATH_MAX): Leave it undefined on GNU/Hurd. + * lib/chdir-long.h: Include pathmax.h. + * lib/clean-temp.c (PATH_MAX): Remove code that is done by pathmax.h. + * lib/getcwd.c: Include pathmax.h instead of . + (PATH_MAX): Remove code that is done by pathmax.h. + * lib/canonicalize.c (PATH_MAX): Provide a fallback value. + * lib/tmpfile.c: Add a comment. + * m4/pathmax.m4 (gl_PATHMAX): Don't test for pathconf. + * modules/chdir-long (Depends-on): Add pathmax. + * modules/getcwd (Depends-on): Add pathmax. + * tests/test-getcwd.c (test_abort_bug): Avoid syntax error when PATH_MAX + is not defined. + * doc/posix-headers/limits.texi: Mention the pathmax module. + * NEWS: Mention the change. + 2011-08-02 Bruno Haible pthread_sigmask: Actually use results of gl_THREADLIB. diff --git a/NEWS b/NEWS index 35df925e8..390538358 100644 --- a/NEWS +++ b/NEWS @@ -12,6 +12,11 @@ User visible incompatible changes Date Modules Changes +2011-08-04 pathmax The header file "pathmax.h" no longer defines + PATH_MAX on GNU/Hurd. Please use one of the methods + listed in pathmax.h to ensure your package is + portable to GNU/Hurd. + 2011-07-24 close This module no longer pulls in the 'fclose' module. If your code creates a socket descriptor using socket() or accept(), then a FILE stream referring diff --git a/doc/posix-headers/limits.texi b/doc/posix-headers/limits.texi index 65efb9121..4f18419a4 100644 --- a/doc/posix-headers/limits.texi +++ b/doc/posix-headers/limits.texi @@ -15,3 +15,7 @@ IRIX 6.5, OSF/1 5.1, Solaris 11 2010-11, Cygwin 1.5.x, mingw, Interix 3.5, BeOS. Portability problems not fixed by Gnulib: @itemize @end itemize + +For @code{PATH_MAX}, Gnulib provides a module @code{pathmax} with a header +file @code{"pathmax.h"}. It defines @code{PATH_MAX} to a constant on +platforms with a file name length limit. diff --git a/lib/canonicalize.c b/lib/canonicalize.c index a329a3351..4fe9f308a 100644 --- a/lib/canonicalize.c +++ b/lib/canonicalize.c @@ -31,6 +31,12 @@ #include "xalloc.h" #include "xgetcwd.h" +/* In this file, we cannot handle file names longer than PATH_MAX. + On systems with no file name length limit, use a fallback. */ +#ifndef PATH_MAX +# define PATH_MAX 8192 +#endif + #ifndef DOUBLE_SLASH_IS_DISTINCT_ROOT # define DOUBLE_SLASH_IS_DISTINCT_ROOT 0 #endif diff --git a/lib/chdir-long.h b/lib/chdir-long.h index 1ad9dd826..feff17557 100644 --- a/lib/chdir-long.h +++ b/lib/chdir-long.h @@ -19,11 +19,7 @@ #include #include -#ifndef PATH_MAX -# ifdef MAXPATHLEN -# define PATH_MAX MAXPATHLEN -# endif -#endif +#include "pathmax.h" /* On systems without PATH_MAX, presume that chdir accepts arbitrarily long directory names. */ diff --git a/lib/clean-temp.c b/lib/clean-temp.c index 0ac9fa04e..22e766bc6 100644 --- a/lib/clean-temp.c +++ b/lib/clean-temp.c @@ -59,13 +59,10 @@ #define _(str) gettext (str) -/* GNU Hurd doesn't have PATH_MAX. */ +/* GNU Hurd doesn't have PATH_MAX. Use a fallback. + Temporary directory names are usually not that long. */ #ifndef PATH_MAX -# ifdef MAXPATHLEN -# define PATH_MAX MAXPATHLEN -# else -# define PATH_MAX 1024 -# endif +# define PATH_MAX 1024 #endif #ifndef uintptr_t diff --git a/lib/getcwd.c b/lib/getcwd.c index e52af1856..f09fc3e8d 100644 --- a/lib/getcwd.c +++ b/lib/getcwd.c @@ -57,8 +57,6 @@ # endif #endif -#include - #ifndef MAX # define MAX(a, b) ((a) < (b) ? (b) : (a)) #endif @@ -66,12 +64,12 @@ # define MIN(a, b) ((a) < (b) ? (a) : (b)) #endif +#include "pathmax.h" + +/* In this file, PATH_MAX only serves as a threshold for choosing among two + algorithms. */ #ifndef PATH_MAX -# ifdef MAXPATHLEN -# define PATH_MAX MAXPATHLEN -# else -# define PATH_MAX 1024 -# endif +# define PATH_MAX 8192 #endif #if D_INO_IN_DIRENT diff --git a/lib/pathmax.h b/lib/pathmax.h index c6793f6c4..a1e458c12 100644 --- a/lib/pathmax.h +++ b/lib/pathmax.h @@ -23,7 +23,22 @@ including the terminating NUL byte. PATH_MAX is not defined on systems which have no limit on filename length, - such as GNU/Hurd. */ + such as GNU/Hurd. + + This file does *not* define PATH_MAX always. Programs that use this file + can handle the GNU/Hurd case in several ways: + - Either with a package-wide handling, or with a per-file handling, + - Either through a + #ifdef PATH_MAX + or through a fallback like + #ifndef PATH_MAX + # define PATH_MAX 8192 + #endif + or through a fallback like + #ifndef PATH_MAX + # define PATH_MAX pathconf ("/", _PC_PATH_MAX) + #endif + */ # include @@ -33,11 +48,6 @@ # define _POSIX_PATH_MAX 256 # endif -# if !defined PATH_MAX && defined _PC_PATH_MAX && defined HAVE_PATHCONF -# define PATH_MAX (pathconf ("/", _PC_PATH_MAX) < 1 ? 1024 \ - : pathconf ("/", _PC_PATH_MAX)) -# endif - /* Don't include sys/param.h if it already has been. */ # if defined HAVE_SYS_PARAM_H && !defined PATH_MAX && !defined MAXPATHLEN # include @@ -47,10 +57,6 @@ # define PATH_MAX MAXPATHLEN # endif -# ifndef PATH_MAX -# define PATH_MAX _POSIX_PATH_MAX -# endif - # ifdef __hpux /* On HP-UX, PATH_MAX designates the maximum number of bytes in a filename, *not* including the terminating NUL byte, and is set to 1023. diff --git a/lib/tmpfile.c b/lib/tmpfile.c index 52d72e3bb..c57e0e788 100644 --- a/lib/tmpfile.c +++ b/lib/tmpfile.c @@ -37,6 +37,9 @@ #include "tempname.h" #include "tmpdir.h" +/* PATH_MAX is guaranteed to be defined, because this replacement is only + used on native Windows. */ + /* On Windows, opening a file with _O_TEMPORARY has the effect of passing the FILE_FLAG_DELETE_ON_CLOSE flag to CreateFile(), which has the effect of deleting the file when it is closed - even when the program crashes. diff --git a/m4/pathmax.m4 b/m4/pathmax.m4 index 17b3d648f..0856722c3 100644 --- a/m4/pathmax.m4 +++ b/m4/pathmax.m4 @@ -1,4 +1,4 @@ -# pathmax.m4 serial 8 +# pathmax.m4 serial 9 dnl Copyright (C) 2002-2003, 2005-2006, 2009-2011 Free Software Foundation, dnl Inc. dnl This file is free software; the Free Software Foundation @@ -8,6 +8,5 @@ dnl with or without modifications, as long as this notice is preserved. AC_DEFUN([gl_PATHMAX], [ dnl Prerequisites of lib/pathmax.h. - AC_CHECK_FUNCS_ONCE([pathconf]) AC_CHECK_HEADERS_ONCE([sys/param.h]) ]) diff --git a/modules/chdir-long b/modules/chdir-long index 22236c6cc..a456b1385 100644 --- a/modules/chdir-long +++ b/modules/chdir-long @@ -8,6 +8,7 @@ m4/chdir-long.m4 Depends-on: unistd +pathmax atexit [test $gl_cv_have_arbitrary_file_name_length_limit = yes] fchdir [test $gl_cv_have_arbitrary_file_name_length_limit = yes] fcntl-h [test $gl_cv_have_arbitrary_file_name_length_limit = yes] diff --git a/modules/getcwd b/modules/getcwd index 6b764d21c..7189a9d0e 100644 --- a/modules/getcwd +++ b/modules/getcwd @@ -10,6 +10,7 @@ m4/getcwd.m4 Depends-on: unistd extensions +pathmax [test $REPLACE_GETCWD = 1] mempcpy [test $REPLACE_GETCWD = 1] d-ino [test $REPLACE_GETCWD = 1] memmove [test $REPLACE_GETCWD = 1] diff --git a/tests/test-getcwd.c b/tests/test-getcwd.c index 33810775d..6e8e67ade 100644 --- a/tests/test-getcwd.c +++ b/tests/test-getcwd.c @@ -49,10 +49,12 @@ test_abort_bug (void) size_t desired_depth; size_t d; +#ifdef PATH_MAX /* 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) return 0; +#endif cwd = getcwd (NULL, 0); if (cwd == NULL)