может быть есть какой-то более умный или портабильный способ..
| Код | #include <stdio.h> #include <stdlib.h> #include <termios.h> #include <sys/types.h> #include <sys/stat.h> #include <sys/ioctl.h> #include <fcntl.h>
struct winsize wsz;
int main(){ char c='\0'; int fd=open("/dev/pts/6",O_RDONLY); /** твой tty сам и узнавай */
if (-1==fd) { perror("on open():"); exit(-1); } printf("success on open() current tty\n"); printf("type 'q' to quite or resize and press any other key to retry.."); while ('q'!=(c=getchar())){ printf("calling ioctl to read current size.."); if (ioctl(fd,TIOCGWINSZ,&wsz)){ /** вот она родная... */ printf("failed to get size.\n"); perror("on ioctl:"); exit(-2);
} printf("OK\n"); printf("current terminal size is:%dx%d.\n",wsz.ws_row,wsz.ws_col); printf("type 'q' to quite or resize and press any other key to retry.."); }
printf("Closing open fd.."); close(fd); printf("OK.\nExitting\n"); return 0;
}
|
|