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
/* 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);
}

View File

@@ -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