Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there an equivalent to WinAPI's MAX_PATH under linux/unix?

Tags:

c++

c

linux

unix

posix

If I want to allocate a char array (in C) that is guaranteed to be large enough to hold any valid absolute path+filename, how big does it need to be.

On Win32, there is the MAX_PATH define. What is the equivalent for Unix/linux?

like image 995
AndrewR Avatar asked May 07 '09 07:05

AndrewR


People also ask

What is Max_path in C?

In the Windows API (with some exceptions discussed in the following paragraphs), the maximum length for a path is MAX_PATH, which is defined as 260 characters.

What is Maxpathlen?

Constant defining the maximum length of filenames (including path)


1 Answers

There is a PATH_MAX, but it is a bit problematic. From the bugs section of the realpath(3) man page:

The POSIX.1-2001 standard version of this function is broken by design, since it is impossible to determine a suitable size for the output buffer, resolved_path. According to POSIX.1-2001 a buffer of size PATH_MAX suffices, but PATH_MAX need not be a defined constant, and may have to be obtained using pathconf(3). And asking pathconf(3) does not really help, since, on the one hand POSIX warns that the result of pathconf(3) may be huge and unsuitable for mallocing memory, and on the other hand pathconf(3) may return -1 to signify that PATH_MAXis not bounded.

like image 193
stefanB Avatar answered Sep 21 '22 17:09

stefanB