Subject: PATH_MAX (Re: [PATCH] system_path: use a static buffer)

From: Jonathan Nieder <[email-masked]>
Date: Fri, 18 Mar 2011 06:38:18 -0500

Hi,

Nguyen Thai Ngoc Duy wrote:

> It was pointed out elsewhere [1] that PATH_MAX only specifies max
> length of a path element, not full path. I think we'd need to stay
> away from preallocated PATH_MAX-sized arrays.

No, PATH_MAX is actually the maximum length of a path, and when you
use, say, open(2), it will fail if your path is longer than that.  The
maximum length of a path component on most filesytems is 255 or 256;
PATH_MAX on Linux is 4096.

It is indeed possible to have paths with length longer than that.  The
way to support that is to use relative paths wherever possible, which
does sound to me like an interesting long-term goal (mostly because I
suspect the result would be easier to read and, especially, to reason
about with respect to race conditions).

Hope that helps,
Jonathan