From: op Date: Sat, 10 Jun 2023 07:24:21 +0000 (+0000) Subject: ksh: remove broken special handling of test -t X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=990e11add74694c8596b173c98b63c6c5dddafc1;p=openbsd ksh: remove broken special handling of test -t Drop the vestiges of the pre-POSIX support of `test -t' defaulting to fd 1. It doesn't work and it always succeed since "-t" is treated as a string by default when no argument (fd) is specified. diff by Lucas (lucas [at] sexy [dot] is) with minor change by me. ok millert@ --- diff --git a/bin/ksh/c_test.c b/bin/ksh/c_test.c index 7038a52bfa4..c1e4907331f 100644 --- a/bin/ksh/c_test.c +++ b/bin/ksh/c_test.c @@ -1,4 +1,4 @@ -/* $OpenBSD: c_test.c,v 1.27 2019/06/28 13:34:59 deraadt Exp $ */ +/* $OpenBSD: c_test.c,v 1.28 2023/06/10 07:24:21 op Exp $ */ /* * test(1); version 7-like -- author Erik Baalbergen @@ -156,12 +156,6 @@ c_test(char **wp) } if (argc == 1) { opnd1 = (*te.getopnd)(&te, TO_NONOP, 1); - /* Historically, -t by itself test if fd 1 - * is a file descriptor, but POSIX says its - * a string test... - */ - if (!Flag(FPOSIX) && strcmp(opnd1, "-t") == 0) - break; res = (*te.eval)(&te, TO_STNZE, opnd1, NULL, 1); if (invert & 1) @@ -271,14 +265,11 @@ test_eval(Test_env *te, Test_op op, const char *opnd1, const char *opnd2, case TO_FILGZ: /* -s */ return stat(opnd1, &b1) == 0 && b1.st_size > 0L; case TO_FILTT: /* -t */ - if (opnd1 && !bi_getn(opnd1, &res)) { + if (!bi_getn(opnd1, &res)) { te->flags |= TEF_ERROR; - res = 0; - } else { - /* generate error if in FPOSIX mode? */ - res = isatty(opnd1 ? res : 0); + return 0; } - return res; + return isatty(res); case TO_FILUID: /* -O */ return stat(opnd1, &b1) == 0 && b1.st_uid == ksheuid; case TO_FILGID: /* -G */ @@ -527,7 +518,7 @@ static const char * ptest_getopnd(Test_env *te, Test_op op, int do_eval) { if (te->pos.wp >= te->wp_end) - return op == TO_FILTT ? "1" : NULL; + return NULL; return *te->pos.wp++; } diff --git a/bin/ksh/ksh.1 b/bin/ksh/ksh.1 index cd3bfc3ebf4..9c68d6ba23e 100644 --- a/bin/ksh/ksh.1 +++ b/bin/ksh/ksh.1 @@ -1,8 +1,8 @@ -.\" $OpenBSD: ksh.1,v 1.218 2022/12/26 17:45:27 jmc Exp $ +.\" $OpenBSD: ksh.1,v 1.219 2023/06/10 07:24:21 op Exp $ .\" .\" Public Domain .\" -.Dd $Mdocdate: December 26 2022 $ +.Dd $Mdocdate: June 10 2023 $ .Dt KSH 1 .Os .Sh NAME @@ -2569,20 +2569,6 @@ in non-POSIX mode: alias a='for ' i='j' a i in 1 2; do echo i=$i j=$j; done .Ed -.It -.Ic test . -In POSIX mode, the expression -.Sq Fl t -(preceded by some number of -.Sq \&! -arguments) is always true as it is a non-zero length string; -in non-POSIX mode, it tests if file descriptor 1 is a -.Xr tty 4 -(i.e. the -.Ar fd -argument to the -.Fl t -test may be left out and defaults to 1). .El .Ss Strict Bourne shell mode When the @@ -3857,18 +3843,12 @@ socket. .It Fl s Ar file .Ar file is not empty. -.It Fl t Op Ar fd +.It Fl t Ar fd File descriptor .Ar fd is a .Xr tty 4 device. -If the -.Ic posix -option is not set, -.Ar fd -may be left out, in which case it is taken to be 1 (the behaviour differs due -to the special POSIX rules described above). .It Fl u Ar file .Ar file Ns 's mode has the setuid bit set.