]> hackdaworld.org Git - sound-tools/hdrec.git/commitdiff
added event.c (event api)
authorhackbard <hackbard>
Fri, 8 Aug 2003 04:08:02 +0000 (04:08 +0000)
committerhackbard <hackbard>
Fri, 8 Aug 2003 04:08:02 +0000 (04:08 +0000)
event.c [new file with mode: 0644]

diff --git a/event.c b/event.c
new file mode 100644 (file)
index 0000000..316f0d6
--- /dev/null
+++ b/event.c
@@ -0,0 +1,64 @@
+/*
+ * event.c -- simple event api 
+ *
+ * author: hackbard@hackdaworld.dyndns.org
+ *
+ */
+
+#include <stdio.h>
+#include <sys/time.h>
+
+typedef struct __fd_list {
+       int fd;
+       unsigned char mode;
+       fd_list *next;
+} fd_list;
+
+#define READ 1
+#define WRITE 2
+
+int add_fd(int fd,unsigned char mode,fd_list *fd_list) {
+       fd_list *new;
+       if(fd_list->next==NULL) {
+               if((new=(fd_list *)(malloc(sizeof(fd_list))))==NULL) {
+                       puts("failed allocating fd_list memory");
+                       return -1;
+               }
+               new->fd=fd;
+               new->mode=mode;
+               fd_list->next=new;
+               fd_list->next->next=NULL;
+               return fd;
+       }
+       else add_fd(fd,mode,tv,fd_list->next);
+}
+
+int del_fd(int fd,fd_list *fd_list) {
+       fd_list *tmp;
+       if(fd_list->next->fd==fd) {
+               tmp=fd_list->next;
+               fd_list->next=fd_list->next->next;
+               free(tmp);
+               return fd;
+       }
+       else {
+               if(fd_list->next==NULL) {
+                       puts("didnt find this fd in list!);
+                       return -1;
+               }
+               del_fd(fd,fd_list->next);
+       }
+       return 1;
+}
+
+get_max_fd(fd_list *fd_list) {
+       int test=-1;
+       if(fd_list->next=NULL) return test;
+       else {
+               if(fd_list->fd>test) test=fd_list->fd;
+               get_max_fd(fd_list->next);
+       }
+}
+
+int loop(fd_list *fd_list,timeval tv) {
+