1 /* winsize.c - handle window size changes and information. */
3 /* Copyright (C) 2005 Free Software Foundation, Inc.
5 This file is part of GNU Bash, the Bourne Again SHell.
7 Bash is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 Bash is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with Bash. If not, see <http://www.gnu.org/licenses/>.
25 #include "bashtypes.h"
27 #if defined (HAVE_UNISTD_H)
31 #include <sys/ioctl.h>
33 /* Try to find the definitions of `struct winsize' and TIOGCWINSZ */
35 #if defined (GWINSZ_IN_SYS_IOCTL) && !defined (TIOCGWINSZ)
36 # include <sys/ioctl.h>
37 #endif /* GWINSZ_IN_SYS_IOCTL && !TIOCGWINSZ */
39 #if defined (STRUCT_WINSIZE_IN_TERMIOS) && !defined (STRUCT_WINSIZE_IN_SYS_IOCTL)
41 #endif /* STRUCT_WINSIZE_IN_TERMIOS && !STRUCT_WINSIZE_IN_SYS_IOCTL */
43 /* Not in either of the standard places, look around. */
44 #if !defined (STRUCT_WINSIZE_IN_TERMIOS) && !defined (STRUCT_WINSIZE_IN_SYS_IOCTL)
45 # if defined (HAVE_SYS_STREAM_H)
46 # include <sys/stream.h>
47 # endif /* HAVE_SYS_STREAM_H */
48 # if defined (HAVE_SYS_PTEM_H) /* SVR4.2, at least, has it here */
49 # include <sys/ptem.h>
50 # define _IO_PTEM_H /* work around SVR4.2 1.1.4 bug */
51 # endif /* HAVE_SYS_PTEM_H */
52 # if defined (HAVE_SYS_PTE_H) /* ??? */
54 # endif /* HAVE_SYS_PTE_H */
55 #endif /* !STRUCT_WINSIZE_IN_TERMIOS && !STRUCT_WINSIZE_IN_SYS_IOCTL */
59 /* Return the fd from which we are actually getting input. */
60 #define input_tty() (shell_tty != -1) ? shell_tty : fileno (stderr)
68 #if defined (READLINE)
69 extern void rl_set_screen_size __P((int, int));
71 extern void sh_set_lines_and_columns __P((int, int));
74 get_new_window_size (from_sig, rp, cp)
78 #if defined (TIOCGWINSZ)
83 if (tty >= 0 && (ioctl (tty, TIOCGWINSZ, &win) == 0) &&
84 win.ws_row > 0 && win.ws_col > 0)
86 sh_set_lines_and_columns (win.ws_row, win.ws_col);
87 #if defined (READLINE)
88 rl_set_screen_size (win.ws_row, win.ws_col);