xref: /DragonOS/user/apps/test_fstat/main.c (revision 3959e94df38073fdb80b199777015f95611ba05f)
1 #include <fcntl.h>
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <sys/stat.h>
5 #include <sys/types.h>
6 #include <unistd.h>
7 int main()
8 {
9     int fd = open("/bin/about.elf", O_RDONLY);
10     if (fd == -1)
11         return 0;
12     printf("fd = %d\n", fd);
13     struct stat *st = (struct stat *)malloc(sizeof(struct stat));
14     fstat(fd, st);
15     printf("stat size = %lu\n", sizeof(struct stat));
16     // FIXME 打印数据时内存出错
17     printf("====================\n");
18     printf("st address: %p\n", st);
19     printf("st_dev = %lu\n", (*st).st_dev);
20     printf("st_ino = %lu\n", (*st).st_ino);
21     printf("st_mode = %d\n", (*st).st_mode);
22     printf("st_nlink = %lu\n", (*st).st_nlink);
23     printf("st_uid = %d\n", (*st).st_uid);
24     printf("st_gid = %d\n", (*st).st_gid);
25     printf("st_rdev = %lu\n", (*st).st_rdev);
26     printf("st_size = %ld\n", (*st).st_size);
27     printf("st_blksize = %ld\n", (*st).st_blksize);
28     printf("st_blocks = %ld\n", (*st).st_blocks);
29     printf("st_atim.sec= %ld\tst_atim.nsec= %ld\n", (*st).st_atim.tv_sec, (*st).st_atim.tv_nsec);
30     printf("st_mtim.sec= %ld\tst_mtim.nsec= %ld\n", (*st).st_mtim.tv_sec, (*st).st_mtim.tv_nsec);
31     printf("st_ctim.sec= %ld\tst_ctim.nsec= %ld\n", (*st).st_ctim.tv_sec, (*st).st_ctim.tv_nsec);
32 
33     return 0;
34 }