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