CPlay/winsz.c
2025-12-26 03:25:16 +01:00

31 lines
632 B
C

#include <stdio.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include <string.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);
char buf[1024];
if(w.ws_col < 1024) {
memset(buf, '#', w.ws_col);
buf[w.ws_col] = '\0';
}
printf("%s", buf);
return 0;
}