X-Git-Url: http://pileus.org/git/?a=blobdiff_plain;f=util.c;h=cfe69a9b863e1d1a1b80825c506209b7dffc3f6c;hb=c5d281c2e042c1153109dd46b74ef3d41fcacd93;hp=cb196bffb6e6bb78674e78f76f03aa5b72d023df;hpb=a6f2be4a52a3dd478c0640714c5be9c5cf87c64e;p=wmpus diff --git a/util.c b/util.c index cb196bf..cfe69a9 100644 --- a/util.c +++ b/util.c @@ -55,12 +55,14 @@ list_t *list_append(list_t *head, void *data) return last ? head : node; } -list_t *list_remove(list_t *head, list_t *node) +list_t *list_remove(list_t *head, list_t *node, int freedata) { list_t *next = node->next; list_t *prev = node->prev; if (next) next->prev = prev; if (prev) prev->next = next; + if (freedata) + free(node->data); free(node); return head == node ? next : head; } @@ -89,6 +91,13 @@ list_t *list_find(list_t *list, void *data) } /* Misc */ +int str2num(char *str, int def) +{ + char *end = NULL; + int num = strtol(str, &end, 10); + return end && *end == '\0' ? num : def; +} + int error(char *fmt, ...) { va_list ap;