[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: PATH_MAX on the Hurd
From: |
Bruno Haible |
Subject: |
Re: PATH_MAX on the Hurd |
Date: |
Thu, 4 Aug 2011 04:02:14 +0200 |
User-agent: |
KMail/1.13.6 (Linux/2.6.37.6-0.5-desktop; KDE/4.6.0; x86_64; ; ) |
Hi Simon,
> I'm trying to get gnulib to work on the Hurd, and ran into this in
> test-getcwd.c:
>
> test-getcwd.c: In function 'test_long_name':
> test-getcwd.c:119:11: error: missing binary operator before token "("
>
> The code is:
>
> 29 #include "pathmax.h"
> ...
> 108 static int
> 109 test_long_name (void)
> 110 {
> 111 #ifndef PATH_MAX
> 112 /* The Hurd doesn't define this, so getcwd can't exhibit the
> bug --
> 113 at least not on a local file system. And if we were to
> start worrying
> 114 about remote file systems, we'd have to enable the wrapper
> function
> 115 all of the time, just to be safe. That's not worth the
> cost. */
> 116 return 0;
> 117 #elif ((INT_MAX / (DIR_NAME_SIZE / DOTDOTSLASH_LEN + 1) \
> 118 - DIR_NAME_SIZE - BUF_SLOP) \
> 119 <= PATH_MAX)
> 120 /* FIXME: Assuming there's a system for which this is true,
> 121 this should be done in a compile test. */
> 122 return 0;
>
> In pathmax.h, gnulib sets up a PATH_MAX like this:
>
> # define PATH_MAX (pathconf ("/", _PC_PATH_MAX) < 1 ? 1024 \
> : pathconf ("/", _PC_PATH_MAX))
>
> And of course the #elif fails because PATH_MAX isn't a constant
> expression.
>
> It seems weird for test-getcwd.c to include pathmax.h and then do a
> #ifndef PATH_MAX test?
Yes, this was precisely the topic of the two threads that started at
<http://lists.gnu.org/archive/html/bug-gnulib/2011-06/msg00241.html>
and <http://lists.gnu.org/archive/html/bug-gnulib/2011-06/msg00289.html>.
The root of the problem is that we have two ways to define PATH_MAX:
- <limits.h> defines it only if it can be a literal constant, and keeps
it undefined on the Hurd,
- "pathmax.h" used to provide a definition always.
And these two semantics get messed up.
There was some, but not complete agreement, that we should change the
semantics the "pathmax.h" so that it matches what <limits.h> does in
POSIX. See the last two mails at
<http://lists.gnu.org/archive/html/bug-gnulib/2011-06/msg00328.html>
<http://lists.gnu.org/archive/html/bug-gnulib/2011-06/msg00329.html>.
So here's now the proposed patch once again.
2011-08-03 Bruno Haible <address@hidden>
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 <limits.h>.
(PATH_MAX): Remove code that is done by pathmax.h.
* lib/canonicalize.c (PATH_MAX): Provide a fallback value.
* lib/tmpfile.c (PATH_MAX): Likewise.
* 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.
--- NEWS.orig Thu Aug 4 03:58:44 2011
+++ NEWS Thu Aug 4 03:39:55 2011
@@ -12,6 +12,11 @@
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
--- doc/posix-headers/limits.texi.orig Thu Aug 4 03:58:44 2011
+++ doc/posix-headers/limits.texi Thu Aug 4 03:58:33 2011
@@ -15,3 +15,7 @@
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.
--- lib/canonicalize.c.orig Thu Aug 4 03:58:44 2011
+++ lib/canonicalize.c Thu Aug 4 03:30:22 2011
@@ -31,6 +31,10 @@
#include "xalloc.h"
#include "xgetcwd.h"
+#ifndef PATH_MAX
+# define PATH_MAX 1024
+#endif
+
#ifndef DOUBLE_SLASH_IS_DISTINCT_ROOT
# define DOUBLE_SLASH_IS_DISTINCT_ROOT 0
#endif
--- lib/chdir-long.h.orig Thu Aug 4 03:58:44 2011
+++ lib/chdir-long.h Thu Aug 4 03:31:35 2011
@@ -19,11 +19,7 @@
#include <unistd.h>
#include <limits.h>
-#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. */
--- lib/clean-temp.c.orig Thu Aug 4 03:58:44 2011
+++ lib/clean-temp.c Thu Aug 4 03:32:09 2011
@@ -61,11 +61,7 @@
/* GNU Hurd doesn't have PATH_MAX. */
#ifndef PATH_MAX
-# ifdef MAXPATHLEN
-# define PATH_MAX MAXPATHLEN
-# else
-# define PATH_MAX 1024
-# endif
+# define PATH_MAX 1024
#endif
#ifndef uintptr_t
--- lib/getcwd.c.orig Thu Aug 4 03:58:44 2011
+++ lib/getcwd.c Thu Aug 4 03:33:01 2011
@@ -57,8 +57,6 @@
# endif
#endif
-#include <limits.h>
-
#ifndef MAX
# define MAX(a, b) ((a) < (b) ? (b) : (a))
#endif
@@ -66,12 +64,10 @@
# define MIN(a, b) ((a) < (b) ? (a) : (b))
#endif
+#include "pathmax.h"
+
#ifndef PATH_MAX
-# ifdef MAXPATHLEN
-# define PATH_MAX MAXPATHLEN
-# else
-# define PATH_MAX 1024
-# endif
+# define PATH_MAX 1024
#endif
#if D_INO_IN_DIRENT
--- lib/pathmax.h.orig Thu Aug 4 03:58:44 2011
+++ lib/pathmax.h Thu Aug 4 03:29:29 2011
@@ -23,7 +23,22 @@
including the terminating NUL byte.
<http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/limits.h.html>
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 <unistd.h>
@@ -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 <sys/param.h>
@@ -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.
--- lib/tmpfile.c.orig Thu Aug 4 03:58:44 2011
+++ lib/tmpfile.c Thu Aug 4 03:41:02 2011
@@ -37,6 +37,10 @@
#include "tempname.h"
#include "tmpdir.h"
+#ifndef PATH_MAX
+# define PATH_MAX 1024
+#endif
+
/* 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.
--- m4/pathmax.m4.orig Thu Aug 4 03:58:44 2011
+++ m4/pathmax.m4 Thu Aug 4 03:18:49 2011
@@ -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 @@
AC_DEFUN([gl_PATHMAX],
[
dnl Prerequisites of lib/pathmax.h.
- AC_CHECK_FUNCS_ONCE([pathconf])
AC_CHECK_HEADERS_ONCE([sys/param.h])
])
--- modules/chdir-long.orig Thu Aug 4 03:58:44 2011
+++ modules/chdir-long Thu Aug 4 03:31:23 2011
@@ -8,6 +8,7 @@
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]
--- modules/getcwd.orig Thu Aug 4 03:58:44 2011
+++ modules/getcwd Thu Aug 4 03:34:12 2011
@@ -10,6 +10,7 @@
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]
--- tests/test-getcwd.c.orig Thu Aug 4 03:58:44 2011
+++ tests/test-getcwd.c Thu Aug 4 03:37:48 2011
@@ -49,10 +49,12 @@
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)
- hurd builds, Simon Josefsson, 2011/08/03
- Re: hurd builds, Paul Eggert, 2011/08/03
- Re: PATH_MAX on the Hurd,
Bruno Haible <=
- Re: PATH_MAX on the Hurd, Paul Eggert, 2011/08/03
- Re: PATH_MAX on the Hurd, Simon Josefsson, 2011/08/04
- Re: PATH_MAX on the Hurd, Bruno Haible, 2011/08/04
- Re: PATH_MAX on the Hurd, Bruno Haible, 2011/08/04
- Re: PATH_MAX on the Hurd, Eric Blake, 2011/08/05
- Re: PATH_MAX on the Hurd, Bruno Haible, 2011/08/05
- Re: PATH_MAX on the Hurd, Paul Eggert, 2011/08/05
- Re: PATH_MAX on the Hurd, Eric Blake, 2011/08/05
- Re: PATH_MAX on the Hurd, Paul Eggert, 2011/08/05