是否有一个相当于WinAPI的的MAX_PATH Linux / Unix下? [英] Is there an equivalent to WinAPI's MAX_PATH under linux/unix?

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

问题描述

如果我想分配一个字符数组(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 ,但它是一个有点问题。从真实路径的错误部分(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)可能是巨大的,
  不适于mallocing存储器,并在另一方面
  的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.

这篇关于是否有一个相当于WinAPI的的MAX_PATH Linux / Unix下?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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