From: Harvie Date: Sun, 6 Nov 2011 13:41:41 +0000 (+0100) Subject: Winsize ioctl terminal size detection example X-Git-Url: https://git.harvie.cz/?a=commitdiff_plain;h=1c19b02656038c9be8abb02e3d0b5201b546899e;p=mirrors%2FPrograms.git Winsize ioctl terminal size detection example --- diff --git a/c/winsize.c b/c/winsize.c new file mode 100644 index 0000000..03c1f7c --- /dev/null +++ b/c/winsize.c @@ -0,0 +1,14 @@ +#include +#include + +static int get_win_size (int fd, struct winsize *win) +{ + int err = ioctl (fd, TIOCGWINSZ, (char *) win); + return err; +} + +int main(void) { + struct winsize win; + if(!get_win_size(1, &win)) puts("Chyba!"); + printf("%d %d :-)\n", win.ws_row, win.ws_col); +}