Alfredo_terabyte

Esercizio struttura stat 2

Sep 14th, 2021
999
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <unistd.h>
  4. #include <sys/stat.h>
  5. #include <dirent.h>
  6.  
  7. int main()
  8. {
  9.     DIR *dp;
  10.     struct dirent *drn;
  11.     char c, gwd[100];
  12.     struct stat buf;
  13.     int fd;
  14.     getcwd(gwd, sizeof(gwd));
  15.     if ((dp = opendir(gwd)) == NULL) {
  16.         printf("Opendir error\n");
  17.         exit(-1);
  18.     }
  19.     while ((drn = readdir(dp)) != NULL) {
  20.         if (lstat(drn->d_name, &buf) < 0) printf("Error lstat su %s\n",drn->d_name);
  21.         if (S_ISLNK(buf.st_mode)) printf("Found link %s\n",drn->d_name);
  22.     }
  23.     exit(0);
  24. }
RAW Paste Data