Where is PATH_MAX defined in Linux?

haziz picture haziz · Feb 26, 2012 · Viewed 175.6k times · Source

Which header file should I invoke with #include to be able to use PATH_MAX as an int for sizing a string?

I want to be able to declare:

char *current_path[PATH_MAX];

But when I do so my compiler (Clang/LLVM on Linux) issues the following error:

recursive_find6.c:29:20: error: use of undeclared identifier 'PATH_MAX'
char *current_path[PATH_MAX];
                   ^

I tried doing a google search but still no luck.

#include <limits.h> Does NOT fix the problem/error.

Am I also correct that the value of PATH_MAX is an int?

Answer

Shiplu Mokaddim picture Shiplu Mokaddim · Feb 26, 2012

Its in linux/limits.h.
#define PATH_MAX 4096 /* # chars in a path name including nul */

#include <linux/limits.h>

char current_path[PATH_MAX];

PATH_MAX has some flaws as mentioned in this blog (thanks paulsm4)