summaryrefslogtreecommitdiff
path: root/src/stty.c
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>1994-01-26 16:08:35 +0000
committerJim Meyering <jim@meyering.net>1994-01-26 16:08:35 +0000
commitac736f7cdc4250cd2a909b6f0a1bf551132cacd5 (patch)
tree76e5b8e71ac6615e8697f7c6fb8401605cac1643 /src/stty.c
parent370edcd71f9fe1eac7ac62799a7114f630de09e3 (diff)
downloadcoreutils-ac736f7cdc4250cd2a909b6f0a1bf551132cacd5.tar.xz
.
Diffstat (limited to 'src/stty.c')
-rw-r--r--src/stty.c22
1 files changed, 19 insertions, 3 deletions
diff --git a/src/stty.c b/src/stty.c
index 98f503f6d..94893a8d1 100644
--- a/src/stty.c
+++ b/src/stty.c
@@ -1069,13 +1069,29 @@ set_speed (type, arg, mode)
}
#ifdef TIOCGWINSZ
+
+/* Get window size information. First try getting the information
+ associated with standard output and if that fails, try standard input.
+ Return zero for success, non-zero if both ioctl's failed. */
+
+static int
+get_win_size (struct winsize *win)
+{
+ int err;
+
+ err = ioctl (1, TIOCGWINSZ, (char *) win);
+ if (err != 0)
+ err = ioctl (0, TIOCGWINSZ, (char *) win);
+ return err;
+}
+
static void
set_window_size (rows, cols)
int rows, cols;
{
struct winsize win;
- if (ioctl (0, TIOCGWINSZ, (char *) &win))
+ if (get_win_size (&win))
{
if (errno != EINVAL)
error (1, errno, "standard input");
@@ -1140,7 +1156,7 @@ display_window_size (fancy)
{
struct winsize win;
- if (ioctl (0, TIOCGWINSZ, (char *) &win))
+ if (get_win_size (&win))
{
if (errno != EINVAL)
error (1, errno, "standard input");
@@ -1161,7 +1177,7 @@ screen_columns ()
#ifdef TIOCGWINSZ
struct winsize win;
- if (ioctl (0, TIOCGWINSZ, (char *) &win))
+ if (get_win_size (&win))
{
/* With Solaris 2.[123], this ioctl fails and errno is set to
EINVAL for telnet (but not rlogin) sessions. */