1
0

fileinfo.c 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. /* statinfo.c - demonstrates using stat() to obtain
  2. * file information.
  3. * - some members are just numbers...
  4. */
  5. #include <stdio.h>
  6. #include <sys/types.h>
  7. #include <sys/stat.h>
  8. void show_stat_info(char *, struct stat *);
  9. int main(int ac, char *av[])
  10. {
  11. struct stat info; /* buffer for file info */
  12. if (ac>1)
  13. if( stat(av[1], &info) != -1 ){
  14. show_stat_info( av[1], &info );
  15. return 0;
  16. }
  17. else
  18. perror(av[1]); /* report stat() errors */
  19. return 1;
  20. }
  21. void show_stat_info(char *fname, struct stat *buf)
  22. /*
  23. * displays some info from stat in a name=value format
  24. */
  25. {
  26. printf(" mode: %o\n", buf->st_mode); /* type + mode */
  27. printf(" links: %d\n", buf->st_nlink); /* # links */
  28. printf(" user: %d\n", buf->st_uid); /* user id */
  29. printf(" group: %d\n", buf->st_gid); /* group id */
  30. printf(" size: %d\n", buf->st_size); /* file size */
  31. printf("modtime: %d\n", buf->st_mtime); /* modified */
  32. printf(" name: %s\n", fname ); /* filename */
  33. }