lol, some bullshit
[sound-tools/hdrec.git] / event.c
1 /*
2  * event.c -- simple event api 
3  *
4  * author: hackbard@hackdaworld.dyndns.org
5  *
6  */
7
8 #include <stdio.h>
9 #include <sys/time.h>
10
11 typedef struct __fd_list {
12         int fd;
13         unsigned char mode;
14         fd_list *next;
15 } fd_list;
16
17 #define READ 1
18 #define WRITE 2
19
20 int add_fd(int fd,unsigned char mode,fd_list *fd_list) {
21         fd_list *new;
22         if(fd_list->next==NULL) {
23                 if((new=(fd_list *)(malloc(sizeof(fd_list))))==NULL) {
24                         puts("failed allocating fd_list memory");
25                         return -1;
26                 }
27                 new->fd=fd;
28                 new->mode=mode;
29                 fd_list->next=new;
30                 fd_list->next->next=NULL;
31                 return fd;
32         }
33         else add_fd(fd,mode,tv,fd_list->next);
34 }
35
36 int del_fd(int fd,fd_list *fd_list) {
37         fd_list *tmp;
38         if(fd_list->next->fd==fd) {
39                 tmp=fd_list->next;
40                 fd_list->next=fd_list->next->next;
41                 free(tmp);
42                 return fd;
43         }
44         else {
45                 if(fd_list->next==NULL) {
46                         puts("didnt find this fd in list!);
47                         return -1;
48                 }
49                 del_fd(fd,fd_list->next);
50         }
51         return 1;
52 }
53
54 get_max_fd(fd_list *fd_list) {
55         int test=-1;
56         if(fd_list->next=NULL) return test;
57         else {
58                 if(fd_list->fd>test) test=fd_list->fd;
59                 get_max_fd(fd_list->next);
60         }
61 }
62
63 int loop(fd_list *fd_list,timeval tv) {
64