Advertisement
Guest User

Untitled

a guest
Oct 20th, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <dirent.h>
  3. #include <string.h>
  4. #include <limits.h>
  5. #include <sys/stat.h>
  6. #include <unistd.h>
  7.  
  8. enum
  9. {
  10. SL_SIZE = 2
  11. };
  12.  
  13. int
  14. main(int argc, char *argv[])
  15. {
  16. DIR *d = opendir(argv[1]);
  17. if (d == NULL) {
  18. return -1;
  19. }
  20. unsigned long long mem = 0;
  21. struct dirent *cur = readdir(d);
  22. while (cur != NULL) {
  23. if (strcmp(cur->d_name, ".") && strcmp(cur->d_name, "..")) {
  24. char name[PATH_MAX];
  25. char sl[SL_SIZE] = "/\0";
  26. if (snprintf(name, PATH_MAX, "%s%s%s", argv[1], sl, cur->d_name) !=
  27. strlen(argv[1]) + strlen(sl) + strlen(cur->d_name)) {
  28. return -1;
  29. }
  30. struct stat cur1;
  31. if (stat(name, &cur1) == 0 && cur1.st_uid == getuid() && S_ISREG(cur1.st_mode) &&
  32. cur->d_name[0] >= 'A' && cur->d_name[0] <= 'Z') {
  33. mem += cur1.st_size;
  34. }
  35. }
  36. cur = readdir(d);
  37. }
  38. printf("%llu\n", mem);
  39. closedir(d);
  40. return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement