On Sat, Jun 18, 2011 at 8:33 PM, Bruno Haible <br...@clisp.org> wrote: > Hi Eric, > > In pathmax.h one of the possible replacement values for PATH_MAX on systems > that don't define it (currently HP-UX and GNU/Hurd) is an expression > involving pathconf(). > > But tests/test-stat.h line 20 declares an array of size PATH_MAX. So - at > least with pre-C99 compilers - it is assuming that PATH_MAX is a constant. > > Should we guarantee that PATH_MAX is a constant expression (by modifying > lib/pathmax.h), or change tests/test-stat.h to not assume it?
It looks to me like POSIX doesn't state that PATH_MAX is a constant expression. There are other values in limits.h that POSIX states must be constant expressions (for example, INT_MAX) so I think this is deliberate. I suspect that the most useful thing we can do in gnulib is define PATH_MAX to a non-constant expression on all platforms, even the ones in which it is normally a constant expression. Otherwise maintainers will find that their code works on their system but won't compile on some other system they don't have access to. Clearly this position on PATH_MAX could be taken to its logical conclusion of un-defining the macro on all platforms to make sure that all GNU programs work on Hurd, but I think that discussion has already been had. In any case, maintainers who want to go in for this can probably achieve the same sort of effect with a syntax check. As for tests/test-stat.h, I'm mildly surprised that we haven't seen any systems where an auto buffer of size PATH_MAX blows the stack. The only purpose for which test-stat.h uses this array is to verify that stat-ing "." and cwd gives the same device/inode. So for this example we can probably just rely on getcwd-lgpl and call getcwd(NULL, 0). James.