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