PATH_MAX not declared when compiling on Ubuntu 10.04
Asked Answered
A

1

7

I am trying to compile a C program in Ubuntu 10.04 made for 8.04. It fails because we have used PATH_MAX and other constants that should be defined in limits.h. According to various resources, it should be part of a POSIX compatible C library.

Is this a bug in Ubuntu 10.04 or is there a proper way of solving this?

Alphonsealphonsine answered 24/11, 2010 at 13:41 Comment(0)
D
10

POSIX defines many such limits to be optional. If a limit FOO is not defined in limits.h, it means the system may have no such limit or the limit might vary at runtime or dependent upon the pathname it's applied to. In these cases, you use the pathconf, fpathconf, or sysconf functions and the _PC_* and _SC_* macros, as in:

path_max = pathconf("/", _PC_PATH_MAX);

or:

page_size = sysconf(_SC_PAGE_SIZE);

Unfortunately GNU (the GNU C library) defines many limits as runtime-variable when they're actually constant on Linux, in some (in my opinion, very misguided) hope that someday the limits will be removed and applications will immediately be able to take advantage of the removal of the limits. However, for application and kernel robustness, it's actually much better to have fixed limits as long as they're sufficiently large (as the Linux limits are).

Delmydeloach answered 24/11, 2010 at 15:41 Comment(3)
It is also, I suspect, an attempt to encourage applications to be portable to systems which have no system-defined limit, such as GNU HURD.Lonni
@caf: I think you figured out the reason exactly.Delmydeloach
you can also find this defined in linux/limits.hProcopius

© 2022 - 2024 — McMap. All rights reserved.