Advertisement
Guest User

stat_st_mode.c

a guest
Apr 4th, 2020
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.62 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <sys/types.h>
  3. #include <sys/stat.h>
  4. #include <unistd.h>
  5. int main(void){
  6.     struct stat sb;
  7.     stat("/tmp", &sb);
  8.     switch (sb.st_mode & S_IFMT) {  /* &  binary AND */
  9.         case S_IFBLK:
  10.             printf("block device node\n");break;
  11.         case S_IFCHR:
  12.             printf("character device node\n");break;
  13.         case S_IFDIR:
  14.             printf("directory\n");break;
  15.         case S_IFIFO:
  16.             printf("FIFO\n");break;
  17.         case S_IFLNK:
  18.             printf("symbolic link\n");break;
  19.         case S_IFREG:
  20.             printf("regular file\n");break;
  21.         case S_IFSOCK:
  22.             printf("socket\n");break;
  23.         default:
  24.             printf("unknown\n");
  25.             break;
  26.     }
  27.     return 0;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement