This commit is contained in:
Your Name 2023-10-21 15:27:42 +03:00
parent 62eafb82ca
commit 78ffcd1cfc

View File

@ -24,7 +24,7 @@ void print(long size, const char *filename) {
printf("%ld\t%s\n", size, filename); printf("%ld\t%s\n", size, filename);
} }
long du(const char *path) { long du(const char *path, int recurs_flag) {
long sum; long sum;
struct stat sb; struct stat sb;
@ -52,17 +52,27 @@ long du(const char *path) {
snprintf(new_path, len, "%s/%s", path, ep->d_name); snprintf(new_path, len, "%s/%s", path, ep->d_name);
sum += du(new_path); sum += du(new_path, 1);
free(new_path); free(new_path);
} }
closedir(dp); closedir(dp);
print(sum, path);
if (s_flag)
if (!recurs_flag) {
print(sum, path);
}
else
print(sum, path);
} }
else else {
sum += sb.st_size; sum = sb.st_size;
if (!recurs_flag)
print(sum, path);
}
return sum; return sum;
} }
@ -98,11 +108,11 @@ int main(const int argc, const char **argv) {
} }
if (argc - i == 0) if (argc - i == 0)
du("."); du(".", 0);
else else
for (; i < argc; i++) for (; i < argc; i++)
du(argv[i]); du(argv[i], 0);
return 0; return 0;
} }