linux最大文件名,Linux路径名和文件名最大长度限制

UNIX标准对路径名和文件名最大长度限制做出了说明,但其上限值在实际应用长过小,Linux在具体实现时提升了该上限,该限制在Linux的 /usr/include/linux/limits.h 中做出了说明,具体如下:

#ifndef _LINUX_LIMITS_H

#define _LINUX_LIMITS_H

#define NR_OPEN            1024

#define NGROUPS_MAX    65536    /* supplemental group IDs are available */

#define ARG_MAX      131072    /* # bytes of args + environ for exec() */

#define LINK_MAX        127    /* # links a file may have */

#define MAX_CANON        255    /* size of the canonical input queue */

#define MAX_INPUT        255    /* size of the type-ahead buffer */

#define NAME_MAX        255    /* # 文件名最大字符数 */

#define PATH_MAX        4096    /* # 相对路径名最大字符数 */

#define PIPE_BUF        4096    /* # bytes in atomic write to a pipe */

#define XATTR_NAME_MAX  255    /* # chars in an extended attribute name */

#define XATTR_SIZE_MAX 65536    /* size of an extended attribute value (64k) */

#define XATTR_LIST_MAX 65536    /* size of extended attribute namelist (64k) */

#define RTSIG_MAX      32

#endif

上述文件内容的第11行和第12行分别说明了文件名和相对路径名的最大长度。需要说明的是,字符指的是ASCII字符,如果是汉字或者其他语言,则需要视编码而定。

上述头文件可以被包含到程序中,然后直接加以引用,这些值也可以使用pathconf( )函数来查询,pathconf( )函数的参数可以参阅该文章中的表格:

一个简单示例demonstration如下:

#include

#include

using namespace std;

int main()

{

cout << pathconf("/",_PC_NAME_MAX) << endl;return 0;

}

0b1331709591d260c1c78e86d0c51c18.png

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值