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

纵饮孤独 提交于 2019-12-18 14:55:53

问题


I am having trouble finding this information, and trial and error is telling me that the value is very high. So I figured I ask the community to see if anyone knows and can point me to a apple page that confirms the length for Lion. All I know is it is larger that Snow Leopard.


回答1:


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.




回答2:


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




回答3:


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




回答4:


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.



来源:https://stackoverflow.com/questions/7140575/mac-os-x-lion-what-is-the-max-path-length

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!