UNIX标准描述了路径名和文件名的最大长度限制,但实际长度太小。 Linux在具体实现时提高了这个上限。 Linux的/usr/include/linux/limits.h中介绍了此限制。 具体情况如下:
#ifndef _LINUX_LIMITS_H
#define _LINUX_LIMITS_H
#define NR_OPEN 1024
# definen groups _ max 65536/* supplementalgroupidsareavailable * /
# define arg _ max 131072/* # bytesofargsenvironforexec (* /
# define link _ max 127/* # linksafilemayhave * /
# definemax _ canon 255/* sizeofthecanonicalinputqueue * /
# definemax _ input 255/* sizeof the type-ahead buffer * /
#define NAME_MAX 255 /* #文件名的最大字符数*/
#define PATH_MAX 4096 /* #相对路径名最大字符数*/
# define pipe _ buf 4096/* # bytesinatomicwritetoapipe * /
# define xattr _ name _ max 255/* # charsinanextendedattributename * /
# define xattr _ size _ max 65536/* sizeofanextendedattributevalue (64k ) /
# define xattr _ list _ max 65536/* sizeofextendedattributenamelist (64k ) /
#define RTSIG_MAX 32
#endif
上述文件内容的第11行和第12行分别表示文件名和相对路径名的最大长度。 此外,字符是指ASCII字符,对于汉字和其他语言,根据代码的不同而不同。
上述头文件可以包含在程序中直接引用。 您也可以使用pathconf ()函数查询这些值,如本文中的表所示。
简单的例子demonstration如下。
#包含
#包含
using namespace std;
int main () )
{
coutpathconf('/',_PC_NAME_MAX ) endl; 返回0;
}