Prefer newer TIOCGWINSZ ioctl to old TIOCGSIZE

This commit is contained in:
Todd C. Miller
2010-10-02 17:11:07 -04:00
parent 6b4fe798d5
commit 1a4990f571
2 changed files with 20 additions and 20 deletions

View File

@@ -70,11 +70,11 @@
#define TERM_RAW 1 #define TERM_RAW 1
/* Compatibility with older tty systems. */ /* Compatibility with older tty systems. */
#if !defined(TIOCGSIZE) && defined(TIOCGWINSZ) #if !defined(TIOCGWINSZ) && defined(TIOCGSIZE)
# define TIOCGSIZE TIOCGWINSZ # define TIOCGWINSZ TIOCGSIZE
# define TIOCSSIZE TIOCSWINSZ # define TIOCSWINSZ TIOCSSIZE
# define ttysize winsize # define winsize ttysize
# define ts_cols ws_col # define ws_cols ts_col
#endif #endif
struct io_buffer { struct io_buffer {
@@ -1143,12 +1143,12 @@ exec_pty(struct command_details *details, char *argv[], char *envp[])
static void static void
sync_ttysize(int src, int dst) sync_ttysize(int src, int dst)
{ {
#ifdef TIOCGSIZE #ifdef TIOCGWINSZ
struct ttysize tsize; struct winsize wsize;
pid_t pgrp; pid_t pgrp;
if (ioctl(src, TIOCGSIZE, &tsize) == 0) { if (ioctl(src, TIOCGWINSZ, &wsize) == 0) {
ioctl(dst, TIOCSSIZE, &tsize); ioctl(dst, TIOCSWINSZ, &wsize);
if ((pgrp = tcgetpgrp(dst)) != -1) if ((pgrp = tcgetpgrp(dst)) != -1)
killpg(pgrp, SIGWINCH); killpg(pgrp, SIGWINCH);
} }

View File

@@ -36,24 +36,24 @@
#include "missing.h" #include "missing.h"
#if !defined(TIOCGSIZE) && defined(TIOCGWINSZ) /* Compatibility with older tty systems. */
# define TIOCGSIZE TIOCGWINSZ #if !defined(TIOCGWINSZ) && defined(TIOCGSIZE)
# define ttysize winsize # define TIOCGWINSZ TIOCGSIZE
# define ts_cols ws_col # define winsize ttysize
# define ts_lines ws_row # define ws_cols ts_col
#endif #endif
void void
get_ttysize(int *linep, int *colp) get_ttysize(int *linep, int *colp)
{ {
char *p; char *p;
#ifdef TIOCGSIZE #ifdef TIOCGWINSZ
struct ttysize win; struct winsize wsize;
if (ioctl(STDERR_FILENO, TIOCGSIZE, &win) == 0 && if (ioctl(STDERR_FILENO, TIOCGWINSZ, &wsize) == 0 &&
win.ts_lines != 0 && win.ts_cols != 0) { wsize.ws_lines != 0 && wsize.ws_cols != 0) {
*linep = win.ts_lines; *linep = wsize.ws_lines;
*colp = win.ts_cols; *colp = wsize.ws_cols;
return; return;
} }
#endif #endif