diff options
author | Yorhel <git@yorhel.nl> | 2013-04-28 09:36:18 +0200 |
---|---|---|
committer | Yorhel <git@yorhel.nl> | 2013-04-28 09:36:18 +0200 |
commit | a263d9a03c7b7b57fac8705806cecf4acf2098c9 (patch) | |
tree | 23db3f67d277cd906b8c1f9fdd2ea1f3dadb1057 | |
parent | f26119acda70b85d6ba92a1ff5419d3b7de0f6bc (diff) |
util/{list,logfile}: Abstract list handling from logfile.c to list.h
-rw-r--r-- | src/util/list.h | 16 | ||||
-rw-r--r-- | src/util/logfile.c | 16 |
2 files changed, 18 insertions, 14 deletions
diff --git a/src/util/list.h b/src/util/list.h index 75f6c8c..d3a96be 100644 --- a/src/util/list.h +++ b/src/util/list.h @@ -78,5 +78,21 @@ } while(0) +#define hlist_insert_before(_l, _n, _next) do {\ + (_n)->next = (_next);\ + (_n)->prev = (_next) ? (_next)->prev : NULL;\ + if((_n)->next) (_n)->next->prev = (_n);\ + if((_n)->prev) (_n)->prev->next = (_n);\ + else (_l) = (_n);\ + } while(0) + + +#define hlist_remove(_l, _n) do {\ + if((_n)->next) (_n)->next->prev = (_n)->prev;\ + if((_n)->prev) (_n)->prev->next = (_n)->next;\ + if((_n) == (_l)) (_l) = (_n)->next;\ + } while(0) + + #endif /* vim: set noet sw=4 ts=4: */ diff --git a/src/util/logfile.c b/src/util/logfile.c index 3e79b1f..5d2c932 100644 --- a/src/util/logfile.c +++ b/src/util/logfile.c @@ -74,29 +74,17 @@ logfile_t *logfile_open(const char *fn) { l->fn = strdup(fn); l->fd = -1; - l->next = logfile_list; - l->prev = NULL; - if(logfile_list) - logfile_list->prev = l; - logfile_list = l; - + hlist_insert_before(logfile_list, l, logfile_list); logfile_checkfile(l); - return l; } void logfile_close(logfile_t *l) { - if(l->next) - l->next->prev = l->prev; - if(l->prev) - l->prev->next = l->next; - if(logfile_list == l) - logfile_list = l->next; + hlist_remove(logfile_list, l); if(l->fd >= 0) close(l->fd); - free(l->fn); free(l); } |