permit read -N n (n ≠ -1) and read -t to return partial reads with $? == 1
issue spotted by carstenh, could have been a documentation ambiguity issue (as -N was designed to read and return exactly n bytes), but this resolves it in a way both backwards-compatible and user-pleasing
This commit is contained in:
parent
f03037706c
commit
0bdc395a81
10
funcs.c
10
funcs.c
@ -38,7 +38,7 @@
|
||||
#endif
|
||||
#endif
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.272 2015/05/01 23:16:29 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.273 2015/06/28 14:57:24 tg Exp $");
|
||||
|
||||
#if HAVE_KILLPG
|
||||
/*
|
||||
@ -1964,8 +1964,9 @@ c_read(const char **wp)
|
||||
break;
|
||||
case 0:
|
||||
/* timeout expired for this call */
|
||||
rv = 1;
|
||||
goto c_read_out;
|
||||
bytesread = 0;
|
||||
/* fake EOF read; all cases return 1 */
|
||||
goto c_read_didread;
|
||||
default:
|
||||
bi_errorf("%s: %s", Tselect, cstrerror(errno));
|
||||
rv = 2;
|
||||
@ -1990,6 +1991,7 @@ c_read(const char **wp)
|
||||
goto c_read_readloop;
|
||||
}
|
||||
|
||||
c_read_didread:
|
||||
switch (readmode) {
|
||||
case READALL:
|
||||
if (bytesread == 0) {
|
||||
@ -2012,7 +2014,7 @@ c_read(const char **wp)
|
||||
if (bytesread == 0) {
|
||||
/* end of file reached */
|
||||
rv = 1;
|
||||
xp = Xstring(xs, xp);
|
||||
/* may be partial read: $? = 1, but content */
|
||||
goto c_read_readdone;
|
||||
}
|
||||
xp += bytesread;
|
||||
|
10
mksh.1
10
mksh.1
@ -1,4 +1,4 @@
|
||||
.\" $MirOS: src/bin/mksh/mksh.1,v 1.367 2015/05/23 17:43:20 tg Exp $
|
||||
.\" $MirOS: src/bin/mksh/mksh.1,v 1.368 2015/06/28 14:57:25 tg Exp $
|
||||
.\" $OpenBSD: ksh.1,v 1.159 2015/03/25 12:10:52 jca Exp $
|
||||
.\"-
|
||||
.\" Copyright © 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009,
|
||||
@ -74,7 +74,7 @@
|
||||
.\" with -mandoc, it might implement .Mx itself, but we want to
|
||||
.\" use our own definition. And .Dd must come *first*, always.
|
||||
.\"
|
||||
.Dd $Mdocdate: May 23 2015 $
|
||||
.Dd $Mdocdate: June 28 2015 $
|
||||
.\"
|
||||
.\" Check which macro package we use, and do other -mdoc setup.
|
||||
.\"
|
||||
@ -3832,7 +3832,8 @@ if empty, instead of the ASCII newline character as input line delimiter.
|
||||
.It Fl N Ar z
|
||||
Instead of reading till end-of-line, read exactly
|
||||
.Ar z
|
||||
bytes; less if EOF or a timeout occurs.
|
||||
bytes.
|
||||
If EOF or a timeout occurs, a partial read is returned with exit status 1.
|
||||
.It Fl n Ar z
|
||||
Instead of reading till end-of-line, read up to
|
||||
.Ar z
|
||||
@ -3851,6 +3852,9 @@ The argument must immediately follow the option character.
|
||||
Interrupt reading after
|
||||
.Ar n
|
||||
seconds (specified as positive decimal value with an optional fractional part).
|
||||
The exit status of
|
||||
.Nm read
|
||||
is 1 if the timeout occurred, but partial reads may still be returned.
|
||||
.It Fl r
|
||||
Normally, the ASCII backslash character escapes the special
|
||||
meaning of the following character and is stripped from the input;
|
||||
|
Loading…
x
Reference in New Issue
Block a user