cxong / tinydir

Lightweight, portable and easy to integrate C directory and file reader

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Not all Linux systems store PATH_MAX in linux/limits.h

sbseltzer opened this issue · comments

I found this out while trying to compile on Alpine Linux, and I'm aware of a number of other distros like it. Systems that conform to POSIX (can't seem to find a clear reference to which standard) will keep it in the standard C limits.h - see comments here. The GNU docs also have some helpful notes on portability.

It's also worth noting that some implementations may have PATH_MAX include null-termination, and others may not. Not sure how you'd want to resolve that.

A more portable way to resolve this issue on POSIX 2001+ systems is to use pathconf as noted here.

We assume that PATH_MAX includes null-termination. In some special cases this would not be good, but it's safe. It seems difficult to figure out whether PATH_MAX includes null-termination or not.

Would including limits.h work for Alpine Linux?
It seems that pathconf will return _POSIX_PATH_MAX, which may not be the same with PATH_MAX in linux/limits.h. (Former is 1024 and latter is 4096 for me)
_POSIX_PATH_MAX should be the minimum value for path in POSIX systems, but not the real limit.