-
Notifications
You must be signed in to change notification settings - Fork 0
/
win.c
48 lines (40 loc) · 957 Bytes
/
win.c
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
39
40
41
42
43
44
45
46
47
48
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <termios.h>
#include <unistd.h>
#ifdef TIOCGWINSZ
#include <sys/ioctl.h>
#endif
#include <asm/ioctls.h>
struct winsize {
unsigned short ws_row;
unsigned short ws_col;
unsigned short ws_xpixel;
unsigned short ws_ypixel;
};
static void pr_winsize(int), sig_winch(int);
#define STDIN_FILENO 0
main()
{
if(isatty(STDIN_FILENO) == 0)
exit(0);
if(signal(SIGWINCH, sig_winch) == SIG_ERR)
exit(0);
pr_winsize(STDIN_FILENO);
for(;;)
pause();
}
static void pr_winsize(int fd)
{
struct winsize size;
if(ioctl(fd, TIOCGWINSZ, (char*)&size) < 0)
exit(0);
printf("%d rows, %d columns\n", size.ws_row, size.ws_col);
}
static void sig_winch(int signo)
{
printf("SIGWINCH recevied\n");
pr_winsize(STDIN_FILENO);
return;
}