Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Get ARG_MAX/PATH_MAX from sysconf/pathconf instead of linux/limits.h
To avoid depending on kernel-related headers when it can be avoided. Note: This means that the values are obtained at run-time rather than at compile-time, but they should not change during runtime. From POSIX.1-2017's sysconf(3p): > This runtime facility is not meant to provide ever-changing values > that applications have to check multiple times. The values are seen > as changing no more frequently than once per system initialization, > such as by a system administrator or operator with an automatic > configuration program. This volume of POSIX.1‐2017 specifies that > they shall not change within the lifetime of the process. > > Some values apply to the system overall and others vary at the file > system or directory level. The latter are described in fpathconf(). Also, use (f)pathconf because (as noted above) PATH_MAX depends on the filesystem of the path in question. From POSIX.1-2017's fpathconf(3p)[2]: > The pathconf() function was proposed immediately after the sysconf() > function when it was realized that some configurable values may differ > across file system, directory, or de‐ vice boundaries. > > For example, {NAME_MAX} frequently changes between System V and > BSD-based file systems; System V uses a maximum of 14, BSD 255. On an > implementation that provides both types of file systems, an > application would be forced to limit all pathname components to 14 > bytes, as this would be the value specified in <limits.h> on such a > system. > > Therefore, various useful values can be queried on any pathname or > file descriptor, assuming that appropriate privileges are in place. Note2: This is not done for all files, as on libtrace.c the macro value is used to define an array size and on firejail.h the value is used in another macro. [1] https://pubs.opengroup.org/onlinepubs/9699919799/functions/sysconf.html [2] https://pubs.opengroup.org/onlinepubs/9699919799/functions/fpathconf.html
- Loading branch information