cat builtin: permit interrupt during writing; more: avoid SIGPIPE
Change-Id: I883dbb359e2580779d7d9fc8e982fbe2a9180668
This commit is contained in:
parent
2a54bce0ae
commit
353204547d
2 changed files with 22 additions and 17 deletions
33
mkshrc
33
mkshrc
|
@ -1,4 +1,4 @@
|
|||
# Copyright (c) 2010, 2012, 2013
|
||||
# Copyright (c) 2010, 2012, 2013, 2014
|
||||
# Thorsten Glaser <tg@mirbsd.org>
|
||||
# This file is provided under the same terms as mksh.
|
||||
#-
|
||||
|
@ -54,20 +54,23 @@ function hd {
|
|||
}
|
||||
|
||||
function more {
|
||||
local dummy line llen curlin=0
|
||||
|
||||
cat "$@" | while IFS= read -r line; do
|
||||
llen=${%line}
|
||||
(( llen == -1 )) && llen=${#line}
|
||||
(( llen = llen ? (llen + COLUMNS - 1) / COLUMNS : 1 ))
|
||||
if (( (curlin += llen) >= LINES )); then
|
||||
print -n -- '\033[7m--more--\033[0m'
|
||||
read -u1 dummy
|
||||
[[ $dummy = [Qq]* ]] && return 0
|
||||
curlin=$llen
|
||||
fi
|
||||
print -r -- "$line"
|
||||
done
|
||||
(
|
||||
set +m
|
||||
cat "$@" |&
|
||||
trap "rv=\$?; kill $! >/dev/null 2>&1; exit \$rv" EXIT
|
||||
while IFS= read -pr line; do
|
||||
llen=${%line}
|
||||
(( llen == -1 )) && llen=${#line}
|
||||
(( llen = llen ? (llen + COLUMNS - 1) / COLUMNS : 1 ))
|
||||
if (( (curlin += llen) >= LINES )); then
|
||||
print -n -- '\033[7m--more--\033[0m'
|
||||
read -u1 || exit $?
|
||||
[[ $REPLY = [Qq]* ]] && exit 0
|
||||
curlin=$llen
|
||||
fi
|
||||
print -r -- "$line"
|
||||
done
|
||||
)
|
||||
}
|
||||
|
||||
function setenv {
|
||||
|
|
|
@ -3761,12 +3761,14 @@ c_cat(const char **wp)
|
|||
break;
|
||||
while (n) {
|
||||
w = write(STDOUT_FILENO, cp, n);
|
||||
eno = errno;
|
||||
/* give the user a chance to ^C out */
|
||||
intrcheck();
|
||||
if (w == -1) {
|
||||
if (errno == EINTR)
|
||||
if (eno == EINTR)
|
||||
/* interrupted, try again */
|
||||
continue;
|
||||
/* an error occured during writing */
|
||||
eno = errno;
|
||||
bi_errorf("%s: %s", "<stdout>",
|
||||
cstrerror(eno));
|
||||
rv = 1;
|
||||
|
|
Loading…
Reference in a new issue