summaryrefslogtreecommitdiff
path: root/Src/utils.c
diff options
context:
space:
mode:
authorPeter Stephenson <pws@users.sourceforge.net>2000-06-26 15:00:27 +0000
committerPeter Stephenson <pws@users.sourceforge.net>2000-06-26 15:00:27 +0000
commitacda8dc2564ea0099c6a948cbbfaaefde81f8652 (patch)
treede212098997401520424c4eea54d15d0b375363f /Src/utils.c
parent326e04c360d3dbb68e7a40a5c21f6284a836fe0d (diff)
downloadzsh-acda8dc2564ea0099c6a948cbbfaaefde81f8652.tar.gz
zsh-acda8dc2564ea0099c6a948cbbfaaefde81f8652.zip
12073: read -t to test for available input before reading
Diffstat (limited to 'Src/utils.c')
-rw-r--r--Src/utils.c33
1 files changed, 25 insertions, 8 deletions
diff --git a/Src/utils.c b/Src/utils.c
index b4be1c4f1..f423795ab 100644
--- a/Src/utils.c
+++ b/Src/utils.c
@@ -1249,7 +1249,7 @@ zstrtol(const char *s, char **t, int base)
/**/
int
-setblock_stdin(void)
+setblock_fd(int turnonblocking, int fd, long *modep)
{
#ifdef O_NDELAY
# ifdef O_NONBLOCK
@@ -1267,15 +1267,24 @@ setblock_stdin(void)
#if NONBLOCK
struct stat st;
- long mode;
- if (!fstat(0, &st) && !S_ISREG(st.st_mode)) {
- mode = fcntl(0, F_GETFL, 0);
- if (mode != -1 && (mode & NONBLOCK) &&
- !fcntl(0, F_SETFL, mode & ~NONBLOCK))
- return 1;
- }
+ if (!fstat(fd, &st) && !S_ISREG(st.st_mode)) {
+ *modep = fcntl(fd, F_GETFL, 0);
+ if (*modep != -1) {
+ if (!turnonblocking) {
+ /* We want to know if blocking was off */
+ if ((*modep & NONBLOCK) ||
+ !fcntl(fd, F_SETFL, *modep | NONBLOCK))
+ return 1;
+ } else if ((*modep & NONBLOCK) &&
+ !fcntl(fd, F_SETFL, *modep & ~NONBLOCK)) {
+ /* Here we want to know if the state changed */
+ return 1;
+ }
+ }
+ } else
#endif /* NONBLOCK */
+ *modep = -1;
return 0;
#undef NONBLOCK
@@ -1283,6 +1292,14 @@ setblock_stdin(void)
/**/
int
+setblock_stdin(void)
+{
+ long mode;
+ return setblock_fd(1, 0, &mode);
+}
+
+/**/
+int
checkrmall(char *s)
{
fprintf(shout, "zsh: sure you want to delete all the files in ");