Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the relation between PATH_MAX and NAME_MAX, and how do I obtain?

In limits.h, and in various places in the POSIX manpages, there are references to PATH_MAX and NAME_MAX. How do these relate to one another? Where is the official documentation for them? How can I obtain them at run time, and (where relevant) compile time for the C, Python, and GNU (shell) environments?

like image 449
Matt Joiner Avatar asked Jul 24 '10 15:07

Matt Joiner


1 Answers

PATH_MAX is the maximum length of a filesystem path. NAME_MAX is the maximum length of a filename (in a particular spot). So, /foo/bar is restricted by PATH_MAX, and only the bar portion has its length limited by NAME_MAX.

You can get these at run time via pathconf, as _PC_PATH_MAX and _PC_NAME_MAX, although standard practice is generally just to use the static macros at compile time. I suppose it would be better to use the run-time option because you could potentially support longer values that way, but I'm not sure what (if any) systems actually provide a return from pathconf which is greater than the value of the POSIX_FOO_MAX values.

like image 73
Borealid Avatar answered Oct 05 '22 00:10

Borealid