macos Mac OS X Lion:最大路径长度是多少?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7140575/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 08:19:55  来源:igfitidea点击:

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

macospathfilesystemsosx-lion

提问by Rodney S. Foley

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.

我无法找到此信息,反复试验告诉我该值非常高。所以我想我会问社区是否有人知道并可以将我指向一个确认 Lion 长度的苹果页面。我只知道雪豹比雪豹大。

采纳答案by Yahia

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

限制取决于使用的文件系统 - OSX 默认使用 HFS Plus...

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

我可以指向的唯一官方文档是HFS Plus 规范,其中记录了文件名长度限制为 255。

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

维基百科暗示 HFS Plus 上的最大路径长度是“无限的”。

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

也许联系 Apple Dev 支持是获取有关限制的确切声明的最可靠方法。

回答by Joe Plante

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,

然后它将有一个 PATH_MAX 常量作为#define。就我而言,

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

您可以将 1024 硬编码为最大路径,但使用这样的常量会使您的代码在新版本中具有可扩展性

回答by wisbucky

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

从 Mac OS X Yosemite 上的实际测试来看,最大路径长度为 1016 个字符。1017 失败。

回答by devon

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

将此命令复制并粘贴到 MacOSX 的终端应用程序(或 iTerm2、xterm 等)中

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

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 nameand pathlengths are defined in the system header file sys/syslimits.hwhich 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 ccbut essentially this example compiles a one line program and prints all the "macro" definitions into a pipe to grepwhich should filter out all but the lines we want to see. Follow man grepdown the rabbit hole for details on pattern matching with regular expressions. Similarly,

这些最大路径长度在系统头文件中定义sys/syslimits.h,其cc(C编译器)读取来自一些默认位置例如/ usr /包括/或在Xcode应用某处。神秘的开关记录在man cc但本质上这个例子编译了一个单行程序并将所有“宏”定义打印到一个管道中,grep该管道应该过滤掉我们想要看到的行之外的所有行。关注man grep兔子洞,了解有关使用正则表达式进行模式匹配的详细信息。相似地,

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

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.

编译一个空程序并打印这个特定系统和编译器特有的所有标准“宏”定义——绝对值得一看。