X-Git-Url: http://sjero.net/git/?a=blobdiff_plain;f=src%2Futils.c;h=fca15800248351052a573cb2582eb8eb466a91a1;hb=cdcf67a5bdae9c56d263ebf7608b52701851cf22;hp=01cc422ee1d33898920ab1882985be861a9d047a;hpb=4d352013ac8b822fd334115928527824093f83fe;p=wget diff --git a/src/utils.c b/src/utils.c index 01cc422e..fca15800 100644 --- a/src/utils.c +++ b/src/utils.c @@ -50,6 +50,9 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #endif #include #include +#ifdef HAVE_SYS_IOCTL_H +# include +#endif #include "wget.h" #include "utils.h" @@ -1704,3 +1707,28 @@ html_quote_string (const char *s) *p = '\0'; return res; } + +/* Determine the width of the terminal we're running on. If that's + not possible, return 0. */ + +int +determine_screen_width (void) +{ + /* If there's a way to get the terminal size using POSIX + tcgetattr(), somebody please tell me. */ +#ifndef TIOCGWINSZ + return 0; +#else /* TIOCGWINSZ */ + int fd; + struct winsize wsz; + + if (opt.lfilename != NULL) + return 0; + + fd = fileno (stderr); + if (ioctl (fd, TIOCGWINSZ, &wsz) < 0) + return 0; /* most likely ENOTTY */ + + return wsz.ws_col; +#endif /* TIOCGWINSZ */ +}