[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: PATH_MAX constant expression
From: |
Bruno Haible |
Subject: |
Re: PATH_MAX constant expression |
Date: |
Tue, 21 Jun 2011 00:34:51 +0200 |
User-agent: |
KMail/1.9.9 |
Eric Blake wrote:
> Actually, I agree with the first:
>
> > 2011-06-18 Bruno Haible <address@hidden>
> >
> > pathmax: Ensure correct value for PATH_MAX on HP-UX.
> > * lib/pathmax.h (PATH_MAX) [HP-UX]: Define to 1024.
OK, I've committed it now.
> But dislike the second:
>
> > 2011-06-18 Bruno Haible <address@hidden>
> >
> > getcwd tests: Avoid compilation error on HP-UX 11.31.
> > * modules/getcwd-tests (Depends-on): Add pathmax.
> > * tests/test-getcwd.c: Include pathmax.h.
>
> pathmax.h guarantees that PATH_MAX will be defined (even if it is to a
> non-constant value), which is in contrast to <limits.h> that only
> defines it if it is constant.
The gnulib API is meant to look as much like POSIX as possible. The
fact that it defines PATH_MAX in pathmax.h, not <limits.h>, is IMO not
meant as "let's define PATH_MAX to a non-constant expression". Well,
maybe it was in the past, but IMO we should overcome this.
The point of "pathmax.h" is that we cannot augment <limits.h> like we
do for other files. Other than through config.h. But <config.h> must not
#include <sys/param.h>.
There is no single platform I know of, which uses this code branch from
pathmax.h:
# define PATH_MAX (pathconf ("/", _PC_PATH_MAX) < 1 ? 1024 \
: pathconf ("/", _PC_PATH_MAX))
AFAIK, from inspection of the header files, all platforms except GNU/Hurd
and HP-UX nowadays define PATH_MAX to a literal constant. For HP-UX we
know add the value, and for GNU/Hurd we don't.
I find it reasonable to use "#ifdef PATH_MAX" in front of every use of
PATH_MAX, like POSIX requires.
> But later on in test-getcwd, we have code
> that does #ifndef PATH_MAX, which is no longer reachable because of our
> guarantee that PATH_MAX is always defined in pathmax.h.
No, we don't want to guarantee a PATH_MAX on GNU/Hurd.
Here's a proposed patch:
2011-06-20 Bruno Haible <address@hidden>
pathmax: Never define PATH_MAX to a non-constant expression.
* lib/pathmax.h (PATH_MAX): Don't define in terms of pathconf.
* m4/pathmax.m4 (gl_PATHMAX): Don't test for pathconf.
--- lib/pathmax.h.orig Tue Jun 21 00:32:53 2011
+++ lib/pathmax.h Tue Jun 21 00:30:51 2011
@@ -33,11 +33,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>
--- m4/pathmax.m4.orig Tue Jun 21 00:32:53 2011
+++ m4/pathmax.m4 Tue Jun 21 00:31:23 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])
])
--
In memoriam Neda Agha-Soltan <http://en.wikipedia.org/wiki/Neda_Agha-Soltan>
- PATH_MAX on HP-UX, Bruno Haible, 2011/06/18
- Re: PATH_MAX on HP-UX, Eric Blake, 2011/06/20
- Re: PATH_MAX constant expression,
Bruno Haible <=
- Re: PATH_MAX constant expression, Eric Blake, 2011/06/20
- Re: PATH_MAX constant expression, Jim Meyering, 2011/06/21
- Re: PATH_MAX constant expression, Eric Blake, 2011/06/21
- Re: PATH_MAX constant expression, Jim Meyering, 2011/06/21
- Re: PATH_MAX constant expression, Bruno Haible, 2011/06/23
- Re: PATH_MAX constant expression, Jim Meyering, 2011/06/24
- Re: PATH_MAX constant expression, James Youngman, 2011/06/21
- Re: PATH_MAX constant expression, Eric Blake, 2011/06/21