Mac OS X Lion: What is the max path length?

The limits depend on the used filesystem - OSX uses HFS Plus by default...

The only official documents I can point to are the HFS Plus spec which document the limit of 255 for filename length.

Wikipedia hints that the max path length on HFS Plus is "unlimited".

Perhaps contacting Apple Dev support is the most reliable way to get exact statements about limits.


Copy and paste this command into MacOSX's Terminal app (or iTerm2, xterm or the like)

bash$ cc -dM -E -xc - <<< '#include <sys/syslimits.h>' | grep -i ' [NP]A.._MAX'

Press the ⟨return⟩ or ⟨enter⟩ key to run it and get the result:

#define NAME_MAX 255
#define PATH_MAX 1024

These maximum name and path lengths are defined in the system header file sys/syslimits.h which cc (the C compiler) reads from some default location such as /usr/include/ or somewhere in the Xcode app. The cryptic switches are documented in man cc but essentially this example compiles a one line program and prints all the "macro" definitions into a pipe to grep which should filter out all but the lines we want to see. Follow man grep down the rabbit hole for details on pattern matching with regular expressions. Similarly,

bash$ cc -dM -E -xc - <<< ''

compiles an empty program and prints all the standard "macro" definitions peculiar to this particular system and compiler — definitely worth a glance under the hood.


From actual testing on Mac OS X Yosemite, the max path length is 1016 characters. 1017 fails.


Old, but I found an answer:

#include <sys/syslimits.h>

and then it'll have a PATH_MAX constant as a #define. In my case,

char filenameBuffer [PATH_MAX];

You could hardcode 1024 as the maximum path, but using a constant like that makes your code scalable with new releases