summaryrefslogtreecommitdiff
path: root/Src
diff options
context:
space:
mode:
Diffstat (limited to 'Src')
-rw-r--r--Src/Modules/zpty.c2
-rw-r--r--Src/builtin.c34
-rw-r--r--Src/utils.c8
3 files changed, 31 insertions, 13 deletions
diff --git a/Src/Modules/zpty.c b/Src/Modules/zpty.c
index 1be615610..7d33bd064 100644
--- a/Src/Modules/zpty.c
+++ b/Src/Modules/zpty.c
@@ -632,7 +632,7 @@ bin_zpty(char *nam, char **args, Options ops, int func)
if (p->fin)
return 2;
if (OPT_ISSET(ops,'t') && p->read == -1 &&
- !read_poll(p->fd, &p->read, 0))
+ !read_poll(p->fd, &p->read, 0, 0))
return 1;
return (OPT_ISSET(ops,'r') ?
diff --git a/Src/builtin.c b/Src/builtin.c
index 530bba8c8..a8871b9a6 100644
--- a/Src/builtin.c
+++ b/Src/builtin.c
@@ -106,7 +106,7 @@ static struct builtin builtins[] =
BUILTIN("pushln", BINF_PRINTOPTS, bin_print, 0, -1, BIN_PRINT, NULL, "-nz"),
BUILTIN("pwd", 0, bin_pwd, 0, 0, 0, "rLP", NULL),
BUILTIN("r", 0, bin_fc, 0, -1, BIN_R, "nrl", NULL),
- BUILTIN("read", 0, bin_read, 0, -1, 0, "cek:%lnpqrstzu:AE", NULL),
+ BUILTIN("read", 0, bin_read, 0, -1, 0, "cek:%lnpqrst:%zu:AE", NULL),
BUILTIN("readonly", BINF_PLUSOPTS | BINF_MAGICEQUALS | BINF_PSPECIAL, bin_typeset, 0, -1, 0, "AE:%F:%HL:%R:%TUZ:%afghi:%lptux", "r"),
BUILTIN("rehash", 0, bin_hash, 0, 0, 0, "df", "r"),
BUILTIN("return", BINF_PSPECIAL, bin_break, 0, 1, BIN_RETURN, NULL, NULL),
@@ -4189,16 +4189,30 @@ bin_read(char *name, char **args, Options ops, int func)
} else
readfd = izle = 0;
- if (OPT_ISSET(ops,'t') &&
- !read_poll(readfd, &readchar, keys && !zleactive)) {
- if (OPT_ISSET(ops,'k') && !zleactive && !isem)
- settyinfo(&shttyinfo);
- if (haso) {
- fclose(shout);
- shout = oshout;
- SHTTY = -1;
+ if (OPT_ISSET(ops,'t')) {
+ zlong timeout = 0;
+ if (OPT_HASARG(ops,'t')) {
+ mnumber mn = zero_mnumber;
+ mn = matheval(OPT_ARG(ops,'t'));
+ if (errflag)
+ return 1;
+ if (mn.type == MN_FLOAT) {
+ mn.u.d *= 1e6;
+ timeout = (zlong)mn.u.d;
+ } else {
+ timeout = (zlong)mn.u.l * (zlong)1000000;
+ }
+ }
+ if (!read_poll(readfd, &readchar, keys && !zleactive, timeout)) {
+ if (OPT_ISSET(ops,'k') && !zleactive && !isem)
+ settyinfo(&shttyinfo);
+ if (haso) {
+ fclose(shout);
+ shout = oshout;
+ SHTTY = -1;
+ }
+ return 1;
}
- return 1;
}
if (OPT_ISSET(ops,'s') && SHTTY != -1) {
struct ttyinfo ti;
diff --git a/Src/utils.c b/Src/utils.c
index 8534a64cc..64a6a722e 100644
--- a/Src/utils.c
+++ b/Src/utils.c
@@ -1332,7 +1332,7 @@ setblock_stdin(void)
/**/
mod_export int
-read_poll(int fd, int *readchar, int polltty)
+read_poll(int fd, int *readchar, int polltty, zlong microseconds)
{
int ret = -1;
long mode = -1;
@@ -1374,6 +1374,8 @@ read_poll(int fd, int *readchar, int polltty)
gettyinfo(&ti);
if ((polltty = ti.tio.c_cc[VMIN])) {
ti.tio.c_cc[VMIN] = 0;
+ /* termios timeout is 10ths of a second */
+ ti.tio.c_cc[VTIME] = (int) (microseconds / (zlong)100000);
settyinfo(&ti);
}
}
@@ -1381,7 +1383,8 @@ read_poll(int fd, int *readchar, int polltty)
polltty = 0;
#endif
#ifdef HAVE_SELECT
- expire_tv.tv_sec = expire_tv.tv_usec = 0;
+ expire_tv.tv_sec = (int) (microseconds / (zlong)1000000);
+ expire_tv.tv_usec = microseconds % (zlong)1000000;
FD_ZERO(&foofd);
FD_SET(fd, &foofd);
ret = select(fd+1, (SELECT_ARG_2_T) &foofd, NULL, NULL, &expire_tv);
@@ -1407,6 +1410,7 @@ read_poll(int fd, int *readchar, int polltty)
#ifdef HAS_TIO
if (polltty) {
ti.tio.c_cc[VMIN] = 1;
+ ti.tio.c_cc[VTIME] = 0;
settyinfo(&ti);
}
#endif