aboutsummaryrefslogtreecommitdiff
path: root/usr.bin/resizewin/resizewin.c
diff options
context:
space:
mode:
authorEdward Tomasz Napierala <trasz@FreeBSD.org>2017-05-08 08:58:51 +0000
committerEdward Tomasz Napierala <trasz@FreeBSD.org>2017-05-08 08:58:51 +0000
commitf1504c0c26835d89ec4f7176ec1536d467bbf6b0 (patch)
tree533d77be231e8b5c280801843b828508eb7c8816 /usr.bin/resizewin/resizewin.c
parent048fd859cea8ecd2aca85200fbf47a99fb3cc8e0 (diff)
downloadsrc-f1504c0c26835d89ec4f7176ec1536d467bbf6b0.tar.gz
src-f1504c0c26835d89ec4f7176ec1536d467bbf6b0.zip
Notes
Diffstat (limited to 'usr.bin/resizewin/resizewin.c')
-rw-r--r--usr.bin/resizewin/resizewin.c34
1 files changed, 32 insertions, 2 deletions
diff --git a/usr.bin/resizewin/resizewin.c b/usr.bin/resizewin/resizewin.c
index 566577be4d70..20116b615088 100644
--- a/usr.bin/resizewin/resizewin.c
+++ b/usr.bin/resizewin/resizewin.c
@@ -47,20 +47,50 @@ static const char query[] =
"\033[999;999H" /* Move cursor */
"\033[6n" /* Get cursor position */
"\0338"; /* Restore cursor position */
+
+static void
+usage(void)
+{
+
+ fprintf(stderr, "usage: resizewin [-z]\n");
+ exit(1);
+}
+
int
-main(__unused int argc, __unused char **argv)
+main(int argc, char **argv)
{
struct termios old, new;
struct winsize w;
- int ret, fd, cnt, error;
+ int ret, fd, ch, cnt, error, zflag;
char data[20];
struct timeval then, now;
error = 0;
+ zflag = 0;
+ while ((ch = getopt(argc, argv, "z")) != -1) {
+ switch (ch) {
+ case 'z':
+ zflag = 1;
+ break;
+ case '?':
+ default:
+ usage();
+ }
+ }
+ argc -= optind;
+ if (argc != 0)
+ usage();
if ((fd = open("/dev/tty", O_RDWR | O_NONBLOCK)) == -1)
exit(1);
+ if (zflag) {
+ if (ioctl(fd, TIOCGWINSZ, &w) == -1)
+ exit(1);
+ if (w.ws_row != 0 && w.ws_col != 0)
+ exit(0);
+ }
+
/* Disable echo */
if (tcgetattr(fd, &old) == -1)
exit(1);