stat.c 795 B

1234567891011121314151617181920212223242526272829303132333435
  1. #include <sys/stat.h>
  2. #include <stdio.h>
  3. int main(int argc,char *argv[])
  4. {
  5. struct stat s;
  6. int ret;
  7. ret = stat("/",&s);
  8. if(ret<0){
  9. perror("stat");
  10. exit(1);
  11. }
  12. /* The casts are because glibc thinks it's cool */
  13. printf("device : 0x%x\n",(unsigned int)s.st_dev);
  14. printf("inode : %d\n",(int)s.st_ino);
  15. printf("mode : 0x%x\n",s.st_mode);
  16. printf("nlink : %d\n",s.st_nlink);
  17. printf("uid : %d\n",s.st_uid);
  18. printf("gid : %d\n",s.st_gid);
  19. printf("rdev : 0x%x\n",(unsigned int)s.st_rdev);
  20. printf("size : %ld\n",s.st_size);
  21. printf("blksize : %ld\n",s.st_blksize);
  22. printf("blocks : %ld\n",s.st_blocks);
  23. printf("atime : %ld\n",s.st_atime);
  24. printf("mtime : %ld\n",s.st_mtime);
  25. printf("ctime : %ld\n",s.st_ctime);
  26. exit(0);
  27. }