]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - progs/reset_cmd.c
ncurses 6.0 - patch 20161022
[ncurses.git] / progs / reset_cmd.c
index da953eb1218804ed4d8850fa0d61c058dbb5047c..e0831e273c55f8c61a88a39707ccdc5e3c0326e9 100644 (file)
@@ -51,7 +51,7 @@
 #include <sys/ptem.h>
 #endif
 
-MODULE_ID("$Id: reset_cmd.c,v 1.6 2016/08/20 23:53:44 tom Exp $")
+MODULE_ID("$Id: reset_cmd.c,v 1.9 2016/10/23 01:08:11 tom Exp $")
 
 /*
  * SCO defines TIOCGSIZE and the corresponding struct.  Other systems (SunOS,
@@ -98,7 +98,8 @@ failed(const char *msg)
 
     _nc_STRCPY(temp, _nc_progname, sizeof(temp));
     _nc_STRCAT(temp, ": ", sizeof(temp));
-    perror(strncat(temp, msg, sizeof(temp) - strlen(temp) - 2));
+    _nc_STRNCAT(temp, msg, sizeof(temp), sizeof(temp) - strlen(temp) - 2);
+    perror(temp);
     exit_error();
     /* NOTREACHED */
 }
@@ -660,18 +661,26 @@ update_tty_settings(TTY * old_settings, TTY * new_settings)
 }
 
 #if HAVE_SIZECHANGE
-/* Set window size if not set already */
+/*
+ * Set window size if not set already, but update our copy of the values if the
+ * size was set.
+ */
 void
-set_window_size(int fd, int high, int wide)
+set_window_size(int fd, short *high, short *wide)
 {
     STRUCT_WINSIZE win;
     (void) ioctl(fd, IOCTL_GET_WINSIZE, &win);
     if (WINSIZE_ROWS(win) == 0 &&
-       WINSIZE_COLS(win) == 0 &&
-       high > 0 && wide > 0) {
-       WINSIZE_ROWS(win) = (unsigned short) high;
-       WINSIZE_COLS(win) = (unsigned short) wide;
-       (void) ioctl(fd, IOCTL_SET_WINSIZE, &win);
+       WINSIZE_COLS(win) == 0) {
+       if (*high > 0 && *wide > 0) {
+           WINSIZE_ROWS(win) = (unsigned short) *high;
+           WINSIZE_COLS(win) = (unsigned short) *wide;
+           (void) ioctl(fd, IOCTL_SET_WINSIZE, &win);
+       }
+    } else if (WINSIZE_ROWS(win) > 0 &&
+              WINSIZE_COLS(win) > 0) {
+       *high = (short) WINSIZE_ROWS(win);
+       *wide = (short) WINSIZE_COLS(win);
     }
 }
 #endif