在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匹配。 –