Re: [HACKERS] Path-length follies

From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: [HACKERS] Path-length follies
Date: 1999-11-05 00:35:50
Message-ID: Pine.LNX.4.20.9911050030450.29057-100000@peter-e.yi.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

This came and went already but I did some research on it and it doesn't
look as bad as it seems.

On 1999-10-23, Tom Lane mentioned:

> Different parts of the system rely on no fewer than four different
> symbols that they import from several different system header
> files (any one of which might not exist on a particular platform):
> MAXPATHLEN, _POSIX_PATH_MAX, MAX_PATH, PATH_MAX
> And on top of that, postgres.h defines MAXPGPATH which is used
> by yet other places.
>
> On my system, _POSIX_PATH_MAX = 255, PATH_MAX = 1023, MAXPATHLEN = 1024
> (a nearby Linux box is almost but not quite the same) whereas MAXPGPATH
> is 128. So there is absolutely no consistency to the pathname length
> limits being imposed in different parts of Postgres.

The Posix.1 symbol is PATH_MAX, which, in theory, describes the "uniform
system limit". The symbol _POSIX_PATH_MAX defines the minimum which
PATH_MAX is required to be on any Posix system, therefore that value
should be fixed at 255 in the whole world. (Which yields code such as
this:
#ifndef MAXPATHLEN
#define MAXPATHLEN _POSIX_PATH_MAX
#endif
--from the actual source-- conceptually incorrect.)

>From my linux/limits.h (which propagates through to limits.h):
#define PATH_MAX 4095 /* # chars in a path name */

In addition there is FILENAME_MAX, which is even defined if there is, in
fact, no limit on the filename length, in which case it is set to some
really large number. (Thus it is no good for allocating fixed size
buffers.) This seems to be an ANSI C symbol for stdio sort of stuff, not a
kernel thing. (And of course in the GNU "Any Day Now" System, there is no
such limit. ;)

MAXPATHLEN is the BSD name for PATH_MAX. From my sys/param.h:
/* BSD names for some <limits.h> values. */
. . .
#define MAXPATHLEN PATH_MAX

Although this seems to be the most popular thing to use, I can hardly see
it referenced in any documentation at all on this machine.

If one wishes to be anally proper one could use pathconf() to find out the
limits on the fly as they apply to a particular file system.

Finally, the symbol MAX_PATH is not described anywhere and I didn't find
it in the source either.

Which would lead one to suggest the following as portable as possible way
out:

#if defined(PATH_MAX)
#define MAXPGPATH PATH_MAX
#else
#if defined(MAXPATHLEN)
#define MAXPGPATH MAXPATHLEN
#else
#define MAXPGPATH 255 /* because this is the lowest common
denominator on Posix systems */
#endif
#endif

That ought to cover all bases really. And if your system doesn't have
either Posix or BSD includes (whoops!) you can tweak it yourself. Put that
in config.h and everyone is happy.

Then again, I would be even happier if we just used PATH_MAX and not
invent a PostgreSQL-specific constant for everything in the world, but I'm
not sure about the Posix'ness of other systems in the crowd out there. How
about simply:

#ifndef PATH_MAX
#define PATH_MAX 255
#endif

in c.h (not config.h) -- end of story.

(Of course the code would actually have to use this as well. Currently,
MAXPATHLEN is most widespread.)

-Peter

--
Peter Eisentraut Sernanders vaeg 10:115
peter_e(at)gmx(dot)net 75262 Uppsala
http://yi.org/peter-e/ Sweden

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Bruce Momjian 1999-11-05 00:43:23 Re: [HACKERS] New version of psql
Previous Message Stuart Woolford 1999-11-04 23:59:03 Re: [GENERAL] indexed regex select optimisation missing?