#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <error.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <fcntl.h>
int main(int argc, char *argv[])
{
struct stat st;
if (stat(argv[1], &st) < 0)
{
perror("stat() ");
exit(1);
}
mode_t md = st.st_mode;
printf("ISREG %d\n", S_ISREG(md));
printf("ISDIR %d\n", S_ISDIR(md));
printf("ISCHAR %d\n", S_ISCHR(md));
printf("ISBLK %d\n", S_ISBLK(md));
printf("ISLINK %d\n", S_ISLNK(md));
printf("ISSOCKET %d\n", S_ISSOCK(md));
printf("ISPIPE %d\n", S_ISFIFO(md));
exit(0);
}
stat判断文件类型
最新推荐文章于 2024-01-31 18:44:58 发布