From 7db46037c3d70c129e0702a22c91d9928d5dfb0a Mon Sep 17 00:00:00 2001 From: Christian Pointner Date: Fri, 20 Nov 2009 00:59:37 +0000 Subject: added find methods to watch_list diff --git a/watch_list.c b/watch_list.c index 1f5089d..81b850f 100644 --- a/watch_list.c +++ b/watch_list.c @@ -88,6 +88,36 @@ int watch_list_add(watch_list_t* list, int watch_fd, const char* string) return 0; } +char* watch_list_find_path(watch_list_t* list, int watch_fd) +{ + if(!list) + return NULL; + + watch_list_element_t* tmp = list->first_; + while(tmp) { + if(tmp->watch_fd_ == watch_fd) + return tmp->path_; + tmp = tmp->next_; + } + + return NULL; +} + +int watch_list_find_fd(watch_list_t* list, const char* path) +{ + if(!list || !path) + return -1; + + watch_list_element_t* tmp = list->first_; + while(tmp) { + if(tmp->path && !strcmp(path, tmp->path)) + return tmp->path_; + tmp = tmp->next_; + } + + return -1; +} + void watch_list_print(watch_list_t* list, const char* head, const char* sep, const char* tail) { if(!list) diff --git a/watch_list.h b/watch_list.h index 8c3fa63..931b656 100644 --- a/watch_list.h +++ b/watch_list.h @@ -37,6 +37,8 @@ typedef struct watch_list_struct watch_list_t; void watch_list_init(watch_list_t* list); void watch_list_clear(watch_list_t* list); int watch_list_add(watch_list_t* list, int watch_fd, const char* path); +char* watch_list_find_path(watch_list_t* list, int watch_fd); +int watch_list_find_fd(watch_list_t* list, const char* path); void watch_list_print(watch_list_t* list, const char* head, const char* sep, const char* tail); -- cgit v0.10.2