在 linux/unix 下是否有等效于 WinAPI 的 MAX_PATH? [英] Is there an equivalent to WinAPI's MAX_PATH under linux/unix?

查看:22
本文介绍了在 linux/unix 下是否有等效于 WinAPI 的 MAX_PATH?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我想分配一个保证足够大以容纳任何有效绝对路径+文件名的字符数组(在 C 中),它需要多大.

If I want to allocate a char array (in C) that is guaranteed to be large enough to hold any valid absolute path+filename, how big does it need to be.

在 Win32 上,有 MAX_PATH 定义.Unix/linux 的等价物是什么?

On Win32, there is the MAX_PATH define. What is the equivalent for Unix/linux?

推荐答案

有一个PATH_MAX,但是有点问题.从 realpath(3) 手册页的错误部分:

There is a PATH_MAX, but it is a bit problematic. From the bugs section of the realpath(3) man page:

该函数的POSIX.1-2001标准版本被打破设计,因为无法确定合适的尺寸输出缓冲区,resolved_pa​​th.根据 POSIX.1-2001 的缓冲区大小 PATH_MAX 就足够了,但 PATH_MAX 不必是一个定义的常量,可能必须使用 pathconf(3) 获得.和询问 pathconf(3) 并没有真正的帮助,因为,在一方面POSIX 警告 pathconf(3) 的结果可能很大和不适合分配内存,另一方面pathconf(3) 可能会返回 -1 以表示 PATH_MAX 不是有界.

The POSIX.1-2001 standard version of this function is broken by design, since it is impossible to determine a suitable size for the output buffer, resolved_path. According to POSIX.1-2001 a buffer of size PATH_MAX suffices, but PATH_MAX need not be a defined constant, and may have to be obtained using pathconf(3). And asking pathconf(3) does not really help, since, on the one hand POSIX warns that the result of pathconf(3) may be huge and unsuitable for mallocing memory, and on the other hand pathconf(3) may return -1 to signify that PATH_MAXis not bounded.

这篇关于在 linux/unix 下是否有等效于 WinAPI 的 MAX_PATH?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆