blob: 29ebf8382a107878602cf5b1675272a58046f544 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
|
#include <stdio.h>
#include <signal.h>
#include <unistd.h>
#include <sys/ttycom.h>
#include <sys/ioctl.h>
void winhand(int sig) {
struct winsize ws;
ioctl(0,TIOCGWINSZ,&ws);
printf("%d x %d\n",ws.ws_col,ws.ws_row);
}
#if 0
struct winsize {
unsigned short ws_row; /* rows, in characters */
unsigned short ws_col; /* columns, in characters */
unsigned short ws_xpixel; /* horizontal size, pixels */
unsigned short ws_ypixel; /* vertical size, pixels */
};
TIOCGWINSZ struct winsize *ws
Put the window size information associated with the terminal
in the winsize structure pointed to by ws. The window size
structure contains the number of rows and columns (and pixels
if appropriate) of the devices attached to the terminal. It
is set by user software and is the means by which most
full-screen oriented programs determine the screen size. The
winsize structure is defined in <sys/ioctl.h>.
#endif
int main(int argc,char *argv[]) {
winhand(SIGWINCH);
signal(SIGWINCH,winhand);
while(1) {
sleep(100);
}
}
|