PATH_MAX

T

Tristan Miller

Greetings.

I was under the impression that PATH_MAX (i.e., the maximum length, in
characters, of a fully-qualified filename) was part of standard C and
defined in <limits.h>, but apparently I am wrong. (At least, I can't
find it in the C9X draft, and a trivial program using it won't compile
with gcc -ansi.)

Any suggestions for what to replace it with? Is there some relatively
safe arbitrary numerical constant I could use? I.e., what's the
greatest value I'm likely to encounter on today's popular platforms?
I'd hate to pick some value, x, thinking it's "big enough", and then
have some user complain when she tries to input a filename of length
x+1.

The program is aimed at logicians, mathematicians, and computer
scientists, so I expect most of them will be running Windows, DOS,
MacOS, or some variant of Unix (including GNU, Linux, BSD, OS X, etc.).
No need to worry about accommodating obscure embedded systems and
what-not.

Regards,
Tristan
 
J

Jeremy Yallop

Tristan said:
I was under the impression that PATH_MAX (i.e., the maximum length, in
characters, of a fully-qualified filename) was part of standard C and
defined in <limits.h>, but apparently I am wrong. (At least, I can't
find it in the C9X draft, and a trivial program using it won't compile
with gcc -ansi.)

Any suggestions for what to replace it with?

FILENAME_MAX is available to standard C programs. It "expands to an
integer constant expression that is the size needed for an array of
char large enough to hold the longest file name string that the
implementation guarantees can be opened". Note, though, that this is
quite different from the "maximum length [...] of a fully-qualified
filename". Also, some systems have no such maximum, or at least a
maximum that is larger than any array you'd want to allocate. It's
usually better to dynamically allocate the buffer where possible (and
thus handle arrays of arbitrary size).

Jeremy.
 
J

Jeremy Yallop

Tristan said:
I was under the impression that PATH_MAX (i.e., the maximum length, in
characters, of a fully-qualified filename) was part of standard C and
defined in <limits.h>, but apparently I am wrong. (At least, I can't
find it in the C9X draft, and a trivial program using it won't compile
with gcc -ansi.)

Any suggestions for what to replace it with?

FILENAME_MAX is available to standard C programs. It "expands to an
integer constant expression that is the size needed for an array of
char large enough to hold the longest file name string that the
implementation guarantees can be opened". Note, though, that this is
quite different from the "maximum length [...] of a fully-qualified
filename". Also, some systems have no such maximum, or at least a
maximum that is larger than any array you'd want to allocate. It's
usually better to dynamically allocate the buffer where possible (and
thus handle filenames of arbitrary length).

Jeremy.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,266
Messages
2,571,074
Members
48,772
Latest member
Backspace Studios

Latest Threads

Top