ptx: fix an invalid heap reference with short --width
[coreutils.git] / tests / misc / stty.sh
blob5735b764a4af478d3ed97ed13c892c5400e7588d
1 #!/bin/sh
2 # Make sure stty can parse most of its options.
4 # Copyright (C) 1998-2016 Free Software Foundation, Inc.
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 # Make sure there's a tty on stdin.
20 . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
21 print_ver_ stty
23 require_controlling_input_terminal_
24 require_trap_signame_
26 trap '' TTOU # Ignore SIGTTOU
28 # Get the reversible settings from stty.c.
29 stty_reversible_init_
31 saved_state=.saved-state
32 stty --save > $saved_state || fail=1
33 stty $(cat $saved_state) || fail=1
35 # This would segfault prior to sh-utils-2.0j.
36 stty erase - || fail=1
38 # Ensure "immediate" and "wait" mode supported, with and without settings
39 for mode in '-drain' 'drain'; do
40 for opt in 'echo' ''; do
41 stty "$mode" $opt || fail=1
42 done
43 done
45 # These would improperly ignore invalid options through coreutils 5.2.1.
46 returns_ 1 stty -F 2>/dev/null || fail=1
47 returns_ 1 stty -raw -F no/such/file 2>/dev/null || fail=1
48 returns_ 1 stty -raw -a 2>/dev/null || fail=1
50 # Build a list of all boolean options stty accepts on this system.
51 # Don't depend on terminal width. Put each option on its own line,
52 # remove all non-boolean ones, then remove any leading hyphens.
53 sed_del='/^speed/d;/^rows/d;/^columns/d;/ = /d'
54 options=$(stty -a | tr -s ';' '\n' | sed "s/^ //;$sed_del;s/-//g")
56 # Take them one at a time, with and without the leading '-'.
57 for opt in $options; do
58 # 'stty parenb' and 'stty -parenb' fail with this message
59 # stty: standard input: unable to perform all requested operations
60 # on Linux 2.2.0-pre4 kernels. Also since around Linux 2.6.30
61 # other serial control settings give the same error. So skip them.
62 # Also on ppc*|sparc* glibc platforms 'icanon' gives the same error.
63 # See: http://debbugs.gnu.org/7228#14
64 case $opt in
65 parenb|parodd|cmspar) continue;;
66 cstopb|crtscts|cdtrdsr|icanon) continue;;
67 esac
69 # This is listed as supported on FreeBSD
70 # but the ioctl returns ENOTTY.
71 test $opt = extproc && continue
73 stty $opt || fail=1
75 # Likewise, 'stty -cread' would fail, so skip that, too.
76 test $opt = cread && continue
77 if stty_reversible_query_ "$opt" ; then
78 stty -$opt || { fail=1; echo -$opt; }
80 done
82 stty $(cat $saved_state)
84 Exit $fail