开发者

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

I am havin开发者_如何学编程g trouble finding this information, and trial and error is telling me that the value is very high. I figured I would ask the community to see if anyone knows and can point me to an apple page that confirms the length for Lion. All I know is it is larger that Snow Leopard.


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


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.


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜