summaryrefslogtreecommitdiff
path: root/tools.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools.c')
-rw-r--r--tools.c21
1 files changed, 19 insertions, 2 deletions
diff --git a/tools.c b/tools.c
index c43e610f..eb0a14a4 100644
--- a/tools.c
+++ b/tools.c
@@ -4,7 +4,7 @@
* See the main source file 'vdr.c' for copyright information and
* how to reach the author.
*
- * $Id: tools.c 1.6 2000/04/24 13:54:23 kls Exp $
+ * $Id: tools.c 1.7 2000/04/24 15:01:35 kls Exp $
*/
#define _GNU_SOURCE
@@ -22,6 +22,17 @@
int SysLogLevel = 3;
+bool DataAvailable(int filedes)
+{
+ fd_set set;
+ FD_ZERO(&set);
+ FD_SET(filedes, &set);
+ struct timeval timeout;
+ timeout.tv_sec = 0;
+ timeout.tv_usec = 10000;
+ return select(FD_SETSIZE, &set, NULL, NULL, &timeout) > 0 && FD_ISSET(filedes, &set);
+}
+
void writechar(int filedes, char c)
{
write(filedes, &c, sizeof(c));
@@ -41,7 +52,13 @@ char readchar(int filedes)
bool readint(int filedes, int &n)
{
- return read(filedes, &n, sizeof(n)) == sizeof(n);
+ return DataAvailable(filedes) && read(filedes, &n, sizeof(n)) == sizeof(n);
+}
+
+void purge(int filedes)
+{
+ while (DataAvailable(filedes))
+ readchar(filedes);
}
char *readline(FILE *f)