CPlay/winsz.c
2025-11-03 03:06:58 +01:00

21 lines
468 B
C

#include <stdio.h>
#include <sys/ioctl.h>
#include <unistd.h>
int main(void) {
struct winsize w;
/* See: man 2 ioctl */
/* See: man 2 TIOCGWINSZ */
/* See: linux/fs/ioctl.c */
/* See: linux/drivers/tty/tty_io.c (L: ~2709 and ~2359) */
if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &w) == -1) {
perror("ioctl");
return 1;
}
printf("Rows (height): %d\n", w.ws_row);
printf("Cols (width): %d\n", w.ws_col);
return 0;
}