SHARE
TWEET

Untitled

razvanth21 Oct 29th, 2018 84 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <dirent.h>
  4. #include <fcntl.h>
  5. #include <sys/stat.h>
  6. #include <unistd.h>
  7. #include <string.h>
  8.  
  9. int main(int argc, char *argv[])
  10. {
  11.     if(argc != 2)
  12.     {
  13.         printf("Usage: %s <dir> <fis>\n",argv[0]);
  14.         exit(EXIT_FAILURE);
  15.     }
  16.    
  17.     DIR *directory;
  18.    
  19.     if((directory=opendir(argv[1])) < 0)
  20.     {
  21.         printf("Eroare la deschiderea directorului sau parametrul dat nu e un director\n");
  22.         exit(EXIT_FAILURE);
  23.     }
  24.    
  25.     int f;
  26.    
  27.     if((f=open(argv[2],O_WRONLY)) < 0)
  28.     {
  29.         printf("Eroare la deschiderea fisierului pentru scriere sau parametrul dat nu e un fisier\n");
  30.         exit(EXIT_FAILURE);
  31.     }
  32.    
  33.     struct dirent *dir_info;
  34.     struct stat file;
  35.     char buff[512];
  36.    
  37.     while((dir_info=readdir(directory)) != NULL)
  38.     {
  39.         int rez;
  40.         if ((rez = stat(dir_info->d_name, &file)) > 0)
  41.         {
  42.             if (S_ISREG(file.st_mode) && file.st_blocks > 2)
  43.             {
  44.                 snprintf(buff, sizeof(buff), "File %s has %d blocks\n", dir_info->d_name, (int)file.st_blocks);
  45.                
  46.                 printf("%s", buff);
  47.                 write(f, buff, strlen(buff));
  48.             }
  49.         }
  50.     }
  51.    
  52.     closedir(directory);
  53.     close(f);
  54.     return 0;
  55. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top