Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is ARG_MAX not defined via limits.h?

Tags:

linux

limits

On Fedora Core 7, I'm writing some code that relies on ARG_MAX. However, even if I #include <limits.h>, the constant is still not defined. My investigations show that it's present in <sys/linux/limits.h>, but this is supposed to be portable across Win32/Mac/Linux, so directly including it isn't an option. What's going on here?

like image 307
Josh Matthews Avatar asked Sep 05 '08 19:09

Josh Matthews


1 Answers

The reason it's not in limits.h is that it's not a quantity giving the limits of the value range of an integral type based on bit width on the current architecture. That's the role assigned to limits.h by the ISO standard.

The value in which you're interested is not hardware-bound in practice and can vary from platform to platform and perhaps system build to system build.

The correct thing to do is to call sysconf and ask it for "ARG_MAX" or "_POSIX_ARG_MAX". I think that's the POSIX-compliant solution anyway.

Acc. to my documentation, you include one or both of unistd.h or limits.h based on what values you're requesting.

One other point: many implementations of the exec family of functions return E2BIG or a similar value if you try to call them with an oversized environment. This is one of the defined conditions under which exec can actually return.

like image 50
Thomas Kammeyer Avatar answered Nov 12 '22 12:11

Thomas Kammeyer