在sys/stat.h中还定义了更多相关的函数

The following symbolic names for the values of type mode_t shall also be defined.

File type:

S_IFMT
Type of file.
S_IFBLK
Block special.
S_IFCHR
Character special.
S_IFIFO
FIFO special.
S_IFREG
Regular.
S_IFDIR
Directory.
S_IFLNK
Symbolic link.
S_IFSOCK
Socket.
File mode bits:

S_IRWXU
Read, write, execute/search by owner.
S_IRUSR
Read permission, owner.
S_IWUSR
Write permission, owner.
S_IXUSR
Execute/search permission, owner.
S_IRWXG
Read, write, execute/search by group.
S_IRGRP
Read permission, group.
S_IWGRP
Write permission, group.
S_IXGRP
Execute/search permission, group.
S_IRWXO
Read, write, execute/search by others.
S_IROTH
Read permission, others.
S_IWOTH
Write permission, others.
S_IXOTH
Execute/search permission, others.
S_ISUID
Set-user-ID on execution.
S_ISGID
Set-group-ID on execution.
S_ISVTX
[XSI] On directories, restricted deletion flag.
The bits defined by S_IRUSR, S_IWUSR, S_IXUSR, S_IRGRP, S_IWGRP, S_IXGRP, S_IROTH, S_IWOTH, S_IXOTH, S_ISUID, S_ISGID, [XSI] and S_ISVTX shall be unique.

S_IRWXU is the bitwise-inclusive OR of S_IRUSR, S_IWUSR, and S_IXUSR.

S_IRWXG is the bitwise-inclusive OR of S_IRGRP, S_IWGRP, and S_IXGRP.

S_IRWXO is the bitwise-inclusive OR of S_IROTH, S_IWOTH, and S_IXOTH.

Implementations may OR other implementation-defined bits into S_IRWXU, S_IRWXG, and S_IRWXO, but they shall not overlap any of the other bits defined in this volume of IEEE Std 1003.1-2001. The file permission bits are defined to be those corresponding to the bitwise-inclusive OR of S_IRWXU, S_IRWXG, and S_IRWXO.

The following macros shall be provided to test whether a file is of the specified type. The value m supplied to the macros is the value of st_mode from a stat structure. The macro shall evaluate to a non-zero value if the test is true; 0 if the test is false.

S_ISBLK(m)
Test for a block special file.
S_ISCHR(m)
Test for a character special file.
S_ISDIR(m)
Test for a directory.
S_ISFIFO(m)
Test for a pipe or FIFO special file.
S_ISREG(m)
Test for a regular file.
S_ISLNK(m)
Test for a symbolic link.
S_ISSOCK(m)
Test for a socket.

S_ISDIR()函数功能是判断一个路径是否为目录在sys/stat.h中还定义了更多相关的函数The following symbolic names for the values of type mode_t shall also be defined.File type:S_IFMTType of file.S_IFBLKBlock special. 从这个位置——格式符所在位置对应字符串中的位置 %[n]s:从这个位置读取指定宽度的数据 %[aBc]:从这个位置读取aBc中的一个,如果这个位置的第一个匹配失败,就不再匹配了,如果匹配成功,继续匹配直到匹配到不aBc中的字符为止 %[a-z]:从这个位置读取a到z中的任意字符,直到遇到不是a到z.. S_ISREG(st_mode) // 是否是一个常规文件. S_ ISDIR (st_mode) // 是否是一个目录 S_ISCHR(st_mode) // 是否是一个字符设备. S_ISBLK(st_mode) // 是否是一个块设备 S_ISF... S_IFSOCK 0140000 socket //套接字文件 S_IFLNK 0120000 symbolic link //链接文件 S_IFREG 0100000 regular file //普通文件 S_IFBLK...