Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <dirent.h>
- #include <string.h>
- #include <limits.h>
- #include <sys/stat.h>
- #include <unistd.h>
- enum
- {
- SL_SIZE = 2
- };
- int
- main(int argc, char *argv[])
- {
- DIR *d = opendir(argv[1]);
- if (d == NULL) {
- return -1;
- }
- unsigned long long mem = 0;
- struct dirent *cur = readdir(d);
- while (cur != NULL) {
- if (strcmp(cur->d_name, ".") && strcmp(cur->d_name, "..")) {
- char name[PATH_MAX];
- char sl[SL_SIZE] = "/\0";
- if (snprintf(name, PATH_MAX, "%s%s%s", argv[1], sl, cur->d_name) !=
- strlen(argv[1]) + strlen(sl) + strlen(cur->d_name)) {
- return -1;
- }
- struct stat cur1;
- if (stat(name, &cur1) == 0 && cur1.st_uid == getuid() && S_ISREG(cur1.st_mode) &&
- cur->d_name[0] >= 'A' && cur->d_name[0] <= 'Z') {
- mem += cur1.st_size;
- }
- }
- cur = readdir(d);
- }
- printf("%llu\n", mem);
- closedir(d);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement