summaryrefslogtreecommitdiffstats
path: root/mbbsd
diff options
context:
space:
mode:
authorpiaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2005-06-08 15:53:42 +0800
committerpiaip <piaip@63ad8ddf-47c3-0310-b6dd-a9e9d9715204>2005-06-08 15:53:42 +0800
commit0a42448aae0891eb7623b12a7c3cac9b6d0b2151 (patch)
tree6ec8767d89c55e026f809a51a873fb8e349f9924 /mbbsd
parent9ee78d22696759afe55bf1318b4fa86c04be695d (diff)
downloadpttbbs-0a42448aae0891eb7623b12a7c3cac9b6d0b2151.tar
pttbbs-0a42448aae0891eb7623b12a7c3cac9b6d0b2151.tar.gz
pttbbs-0a42448aae0891eb7623b12a7c3cac9b6d0b2151.tar.bz2
pttbbs-0a42448aae0891eb7623b12a7c3cac9b6d0b2151.tar.lz
pttbbs-0a42448aae0891eb7623b12a7c3cac9b6d0b2151.tar.xz
pttbbs-0a42448aae0891eb7623b12a7c3cac9b6d0b2151.tar.zst
pttbbs-0a42448aae0891eb7623b12a7c3cac9b6d0b2151.zip
take look at num_in_buf.
I can't believe that this bug has been existed for at least 3 years more, since the first revision of SVN. (see r1, 03/07/2002) Nobody even noticed that!? git-svn-id: http://opensvn.csie.org/pttbbs/trunk/pttbbs@2801 63ad8ddf-47c3-0310-b6dd-a9e9d9715204
Diffstat (limited to 'mbbsd')
-rw-r--r--mbbsd/io.c39
1 files changed, 38 insertions, 1 deletions
diff --git a/mbbsd/io.c b/mbbsd/io.c
index 414ac3f7..23ee3b47 100644
--- a/mbbsd/io.c
+++ b/mbbsd/io.c
@@ -116,7 +116,7 @@ add_io(int fd, int timeout)
int
num_in_buf(void)
{
- return icurrchar - ibufsize;
+ return ibufsize - icurrchar;
}
/*
@@ -437,6 +437,43 @@ igetch(void)
return 0;
}
+/*
+ * wait user input anything for f seconds.
+ * Return 1 if anything available.
+ */
+int
+wait_input(float f, int flDoRefresh)
+{
+ int sel = 0;
+ fd_set readfds;
+ struct timeval tv;
+
+ if(num_in_buf() > 0)
+ return 1;
+
+ FD_ZERO(&readfds);
+ FD_SET(0, &readfds);
+
+ if(flDoRefresh)
+ refresh();
+ tv.tv_sec = (long) f;
+ tv.tv_usec = (f - (long)f) * 1000000L;
+
+#ifdef STATINC
+ STATINC(STAT_SYSSELECT);
+#endif
+
+ do {
+ sel = select(1, &readfds, NULL, NULL, &tv);
+ } while (sel < 0 && errno == EINTR);
+ /* EINTR, interrupted. I don't care! */
+
+ if(sel == 0)
+ return 0;
+
+ return 1;
+}
+
/**
* 根據 mode 來 strip 字串 str,並把結果存到 buf
* @param buf