ToniDev

Ex2/OS

Jan 11th, 2022
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.76 KB | None | 0 0
  1. #include <sys/types.h>
  2. #include <sys/stat.h>
  3. #include <stdint.h>
  4. #include <time.h>
  5. #include <unistd.h>
  6. #include <stdio.h>
  7. #include <stdlib.h>
  8. #include <sys/sysmacros.h>
  9. #include <dirent.h>
  10.  
  11. int main(int argc, char *argv[])
  12. {
  13.   DIR* d;
  14.   char* nume_fisere = (char*)malloc(100*sizeof(char));
  15.   struct dirent *dir;
  16.   struct stat sb;
  17.   struct tm dt;
  18.  
  19.   if (argc != 2) {
  20.       printf("nu sunt suficiente argumente\n");
  21.       exit(EXIT_FAILURE);
  22.   }
  23.  
  24.   int contor = 0;
  25.   d = opendir(argv[1]);
  26.  
  27.   if (d) { //Verifica daca s-a deschis cu succes folderul
  28.       while ((dir = readdir(d)) != NULL)
  29.       {
  30.           printf("%s\n", dir->d_name);
  31.           nume_fisere[contor] = *dir->d_name;
  32.           contor++;
  33.       }
  34.   }
  35.  
  36.   for (int i = 0; i < contor; i++) {
  37.  
  38.       if(lstat(argv[1], &sb) == -1){
  39.         printf("Eroare fisiere\n");
  40.         exit(EXIT_FAILURE);
  41.       }
  42.  
  43.       //lstat(nume_fisere[i], &sb);
  44.  
  45.       dt = *(gmtime(&sb.st_ctime));
  46.  
  47.       printf("File type:                ");
  48.       printf("I-node number:            %ju\n", (uintmax_t) sb.st_ino);
  49.       printf("Mode:                     %jo (octal)\n", (uintmax_t) sb.st_mode);
  50.       printf("Link count:               %ju\n", (uintmax_t) sb.st_nlink);
  51.       printf("Ownership:                UID=%ju   GID=%ju\n", (uintmax_t) sb.st_uid, (uintmax_t) sb.st_gid);
  52.       printf("Preferred I/O block size: %jd bytes\n", (intmax_t) sb.st_blksize);
  53.       printf("File size:                %jd bytes\n", (intmax_t) sb.st_size);
  54.       printf("Blocks allocated:         %jd\n", (intmax_t) sb.st_blocks);
  55.       printf("Created on:               %d-%d-%d %d:%d:%d\n", dt.tm_mday, dt.tm_mon, dt.tm_year + 1900, dt.tm_hour, dt.tm_min, dt.tm_sec);
  56.  
  57.       printf("\n");
  58.     }
  59.  
  60.     free(nume_fisere);
  61. }
Advertisement
Add Comment
Please, Sign In to add comment