#include <sys/stat.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <time.h>
typedef struct stat ST;
int main()
{
//准备结构体
ST s;
//调用stat函数
int res = stat("a.txt",&s);
if(-1 == res)
perror("error:"),exit(-1);
printf("inode = %d\n",s.st_ino);
printf("mode = %o\n",s.st_mode&07777);
printf("hard = %d\n",s.st_nlink);
printf("uid = %d\n",s.st_uid);
printf("size = %d\n",s.st_size);
printf("blocksize = %d\n",s.st_blksize);
printf("blocks = %d\n",s.st_blocks);
printf("atime = %s",ctime(&s.st_atime));
//使用宏函数检查文件属性
if(S_ISDIR(s.st_mode))
puts("文件夹");
if(S_ISREG(s.st_mode))
puts("普通文件");
}