Advertisement
anechka_ne_plach

Untitled

Feb 21st, 2022
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.11 KB | None | 0 0
  1.    1   │ #include <stdio.h>
  2.    2   │ #include <dirent.h>
  3.    3   │ #include <sys/types.h>
  4.    4   │ #include <sys/stat.h>
  5.    5   │ #include <fcntl.h>
  6.    6   │ #include <stdlib.h>
  7.    7   │ #include <limits.h>
  8.    8   │ #include <ctype.h>
  9.    9   │ #include <unistd.h>
  10.   10   │
  11.   11   │ int main(int argc, char* argv[]) {
  12.   12   │     DIR *d = opendir(argv[1]);
  13.   13   │     struct dirent* dd;
  14.   14   │
  15.   15   │     int64_t sum = 0;
  16.   16   │
  17.   17   │     while ((dd = readdir(d))) {
  18.   18   │         char buf[PATH_MAX];
  19.   19   │         if (snprintf(buf, sizeof(buf), "%s/%s", argv[1], dd->d_name) < sizeof(buf)) {
  20.   20   │             struct stat stb;
  21.   21   │             if (stat(buf, &stb) >= 0 && S_ISREG(stb.st_mode) &&
  22.   22   │                 isupper((unsigned char)dd->d_name[0]) &&
  23.   23   │                 stb.st_uid == getuid())
  24.   24   │             {
  25.   25   │                 sum += stb.st_size;
  26.   26   │             }
  27.   27   │         }
  28.   28   │     }
  29.   29   │     printf("%lld\n", sum);
  30.   30   │
  31.   31   │     closedir(d);
  32.   32   │ }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement