summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>1996-11-24 18:06:35 +0000
committerJim Meyering <jim@meyering.net>1996-11-24 18:06:35 +0000
commit161db26bd18f072d9c72c871ccc36db8d0b0ff1e (patch)
treed8b8701d14472a4ab12ccb1cc1a3a50a00efe101 /src
parenta992c841ae21bafa88c5862c8be9e8ac9c4d8b65 (diff)
downloadcoreutils-161db26bd18f072d9c72c871ccc36db8d0b0ff1e.tar.xz
(get_win_size): Take a FILENO parameter rather than
trying to get a size from both stdin and stdout. Update callers. Use STDIN_FILENO and STDOUT_FILENO instead of literal 0, 1.
Diffstat (limited to 'src')
-rw-r--r--src/stty.c19
1 files changed, 13 insertions, 6 deletions
diff --git a/src/stty.c b/src/stty.c
index 60bbbfded..86a503515 100644
--- a/src/stty.c
+++ b/src/stty.c
@@ -1192,12 +1192,19 @@ set_speed (enum speed_setting type, const char *arg, struct termios *mode)
#ifdef TIOCGWINSZ
+static int
+get_win_size (int fileno, struct winsize *win)
+{
+ int err = ioctl (fileno, TIOCGWINSZ, (char *) win);
+ return err;
+}
+
static void
set_window_size (int rows, int cols)
{
struct winsize win;
- if (ioctl (0, TIOCGWINSZ, (char *) &win))
+ if (get_win_size (STDIN_FILENO, &win))
{
if (errno != EINVAL)
error (1, errno, _("standard input"));
@@ -1241,16 +1248,16 @@ set_window_size (int rows, int cols)
win.ws_row = 1;
win.ws_col = 1;
- if (ioctl (0, TIOCSWINSZ, (char *) &win))
+ if (ioctl (STDIN_FILENO, TIOCSWINSZ, (char *) &win))
error (1, errno, _("standard input"));
- if (ioctl (0, TIOCSSIZE, (char *) &ttysz))
+ if (ioctl (STDIN_FILENO, TIOCSSIZE, (char *) &ttysz))
error (1, errno, _("standard input"));
return;
}
# endif
- if (ioctl (0, TIOCSWINSZ, (char *) &win))
+ if (ioctl (STDIN_FILENO, TIOCSWINSZ, (char *) &win))
error (1, errno, _("standard input"));
}
@@ -1259,7 +1266,7 @@ display_window_size (int fancy)
{
struct winsize win;
- if (ioctl (0, TIOCGWINSZ, (char *) &win))
+ if (get_win_size (STDIN_FILENO, &win))
{
if (errno != EINVAL)
error (1, errno, _("standard input"));
@@ -1288,7 +1295,7 @@ screen_columns (void)
(but it works for ptys).
It can also fail on any system when stdout isn't a tty.
In case of any failure, just use the default. */
- if (ioctl (1, TIOCGWINSZ, (char *) &win) == 0 && win.ws_col > 0)
+ if (get_win_size (STDOUT_FILENO, &win) == 0 && win.ws_col > 0)
return win.ws_col;
#endif
/* FIXME: use xstrtol */