]> CyberLeo.Net >> Repos - SourceForge/afuse.git/blob - src/fd_list.c
Tidying up for release 0.2.
[SourceForge/afuse.git] / src / fd_list.c
1 #define __FD_LIST_C
2
3 #include <errno.h>
4 #include "afuse.h"
5 #include "utils.h"
6 #include "fd_list.h"
7
8 void fd_list_add(fd_list_t **fd_list, int fd)
9 {
10         fd_list_t *new_fd;
11
12         new_fd = my_malloc( sizeof(fd_list_t) );
13         new_fd->fd = fd;
14         new_fd->next = *fd_list;
15         new_fd->prev = NULL;
16
17         *fd_list = new_fd;
18 }
19
20 void fd_list_remove(fd_list_t **fd_list, int fd)
21 {
22         fd_list_t *current_fd = *fd_list;
23         
24         while(current_fd) {
25                 if(current_fd->fd == fd) {
26                         if(current_fd->prev)
27                                 current_fd->prev->next = current_fd->next;
28                         else
29                                 *fd_list = current_fd->next;
30                         if(current_fd->next)
31                                 current_fd->next->prev = current_fd->prev;
32                         free(current_fd);
33
34                         return;
35                 }
36
37                 current_fd = current_fd->next;
38         }
39 }
40
41 void fd_list_close_all(fd_list_t **fd_list)
42 {
43         while(*fd_list) {
44                 int retries;
45                 
46                 for(retries = 0; retries < CLOSE_MAX_RETRIES &&
47                                  close((*fd_list)->fd) == -1   &&
48                                  errno == EINTR;
49                     retries++);
50                 fd_list_remove(fd_list, (*fd_list)->fd);
51         }
52 }
53
54 bool fd_list_empty(fd_list_t *fd_list)
55 {
56         return (fd_list == NULL) ? true : false;
57 }