X-Git-Url: https://fleuret.org/cgi-bin/gitweb/gitweb.cgi?a=blobdiff_plain;f=dus.c;h=c3917841d23cb0cf6d3dbdc734863af702026cd9;hb=7a0d380dce67b3423e207556b38ff77a642b92a4;hp=736b136f795c6d7953259a7a80a0a7666745b06a;hpb=934e451507e97423741a3e38eb591a095c46726b;p=dus.git diff --git a/dus.c b/dus.c index 736b136..c391784 100644 --- a/dus.c +++ b/dus.c @@ -107,7 +107,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 +125,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 +347,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 +421,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);