X-Git-Url: https://fleuret.org/cgi-bin/gitweb/gitweb.cgi?a=blobdiff_plain;f=dus.c;h=04a0c60093e957fae37cfda4d2caf593388ff2ae;hb=cc82e7cda497fc6824ced21c60ef7917828bd90b;hp=736b136f795c6d7953259a7a80a0a7666745b06a;hpb=934e451507e97423741a3e38eb591a095c46726b;p=dus.git diff --git a/dus.c b/dus.c index 736b136..04a0c60 100644 --- a/dus.c +++ b/dus.c @@ -28,6 +28,7 @@ #include #include +#include #include #include #include @@ -107,7 +108,7 @@ size_sum_t file_or_dir_size(const char *name) { struct dirent *dir_e; struct stat dummy; size_sum_t result; - char subname[BUFFER_SIZE]; + char subname[PATH_MAX]; result = 0; @@ -125,7 +126,7 @@ size_sum_t file_or_dir_size(const char *name) { if(dir) { while((dir_e = readdir(dir))) { if(!ignore_entry(dir_e->d_name)) { - snprintf(subname, BUFFER_SIZE, "%s/%s", name, dir_e->d_name); + snprintf(subname, PATH_MAX, "%s/%s", name, dir_e->d_name); result += file_or_dir_size(subname); } } @@ -347,6 +348,7 @@ void print_help(FILE *out) { int main(int argc, char **argv) { int c; struct file_with_size *root; + struct winsize win; root = 0; @@ -420,12 +422,8 @@ int main(int argc, char **argv) { } } - if(isatty(STDOUT_FILENO)) { - struct winsize win; - if(ioctl (STDOUT_FILENO, TIOCGWINSZ, (char *) &win)) { - fprintf(stderr, "Can not get the tty size: %s\n", strerror(errno)); - exit (EXIT_FAILURE); - } + if(isatty(STDOUT_FILENO) && + !ioctl (STDOUT_FILENO, TIOCGWINSZ, (char *) &win)) { print_sorted(root, win.ws_col, win.ws_row - 2); } else { print_sorted(root, -1, -1);