在struct dirent定义中,我对使用d_name[256]
和NAME_MAX
感到困惑。 d_name[256]
是否意味着文件名长度可以是最多256个字符?然后它也提到了NAME_MAX(在底部引用)。那么,我的问题是如何与NAME_MAX
相关,我在哪里可以找到NAME_MAX
的价值和定义?C d_name [256]和NAME_MAX定义中的struct dirent
man readdir
struct dirent
定义如下。
struct dirent {
ino_t d_ino; /* inode number */
off_t d_off; /* not an offset; see NOTES */
unsigned short d_reclen; /* length of this record */
unsigned char d_type; /* type of file; not supported
by all filesystem types */
char d_name[256]; /* filename */
};
它还声称,
在的dirent结构的唯一字段由POSIX.1 规定是:
d_name[]
,未指定大小,具有至多NAME_MAX
字符 终止空前述字节('\ 0');和(作为XSI exten- sion)d_ino
。其他领域没有标准化,并且在所有系统上不存在 ;有关更多详细信息,请参阅下面的注释。
NAME_MAX不包含终止符,只是strlen,所以它与d_name匹配。 –