From 1a4990f571539d93a94f38df3650620fe7edbe86 Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Sat, 2 Oct 2010 17:11:07 -0400 Subject: [PATCH] Prefer newer TIOCGWINSZ ioctl to old TIOCGSIZE --- src/exec_pty.c | 18 +++++++++--------- src/ttysize.c | 22 +++++++++++----------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/src/exec_pty.c b/src/exec_pty.c index e77b60bc7..106a00f52 100644 --- a/src/exec_pty.c +++ b/src/exec_pty.c @@ -70,11 +70,11 @@ #define TERM_RAW 1 /* Compatibility with older tty systems. */ -#if !defined(TIOCGSIZE) && defined(TIOCGWINSZ) -# define TIOCGSIZE TIOCGWINSZ -# define TIOCSSIZE TIOCSWINSZ -# define ttysize winsize -# define ts_cols ws_col +#if !defined(TIOCGWINSZ) && defined(TIOCGSIZE) +# define TIOCGWINSZ TIOCGSIZE +# define TIOCSWINSZ TIOCSSIZE +# define winsize ttysize +# define ws_cols ts_col #endif struct io_buffer { @@ -1143,12 +1143,12 @@ exec_pty(struct command_details *details, char *argv[], char *envp[]) static void sync_ttysize(int src, int dst) { -#ifdef TIOCGSIZE - struct ttysize tsize; +#ifdef TIOCGWINSZ + struct winsize wsize; pid_t pgrp; - if (ioctl(src, TIOCGSIZE, &tsize) == 0) { - ioctl(dst, TIOCSSIZE, &tsize); + if (ioctl(src, TIOCGWINSZ, &wsize) == 0) { + ioctl(dst, TIOCSWINSZ, &wsize); if ((pgrp = tcgetpgrp(dst)) != -1) killpg(pgrp, SIGWINCH); } diff --git a/src/ttysize.c b/src/ttysize.c index b84efb0ca..4060ab96d 100644 --- a/src/ttysize.c +++ b/src/ttysize.c @@ -36,24 +36,24 @@ #include "missing.h" -#if !defined(TIOCGSIZE) && defined(TIOCGWINSZ) -# define TIOCGSIZE TIOCGWINSZ -# define ttysize winsize -# define ts_cols ws_col -# define ts_lines ws_row +/* Compatibility with older tty systems. */ +#if !defined(TIOCGWINSZ) && defined(TIOCGSIZE) +# define TIOCGWINSZ TIOCGSIZE +# define winsize ttysize +# define ws_cols ts_col #endif void get_ttysize(int *linep, int *colp) { char *p; -#ifdef TIOCGSIZE - struct ttysize win; +#ifdef TIOCGWINSZ + struct winsize wsize; - if (ioctl(STDERR_FILENO, TIOCGSIZE, &win) == 0 && - win.ts_lines != 0 && win.ts_cols != 0) { - *linep = win.ts_lines; - *colp = win.ts_cols; + if (ioctl(STDERR_FILENO, TIOCGWINSZ, &wsize) == 0 && + wsize.ws_lines != 0 && wsize.ws_cols != 0) { + *linep = wsize.ws_lines; + *colp = wsize.ws_cols; return; } #endif