mirror of
https://git.rwth-aachen.de/acs/public/villas/node/
synced 2025-03-09 00:00:00 +01:00
fixed list_count() and list_contains() -- messed return codes..
This commit is contained in:
parent
8e9bca3dde
commit
00b0457102
2 changed files with 8 additions and 4 deletions
10
lib/list.c
10
lib/list.c
|
@ -81,7 +81,11 @@ void list_remove(struct list *l, void *p)
|
|||
void * list_lookup(struct list *l, const char *name)
|
||||
{
|
||||
int cmp_helper(const void *a, const void *b) {
|
||||
return strcmp(* (char **) a, b);
|
||||
const struct {
|
||||
char *name;
|
||||
} *obj = a;
|
||||
|
||||
return strcmp(obj->name, b);
|
||||
}
|
||||
|
||||
return list_search(l, cmp_helper, (void *) name);
|
||||
|
@ -90,7 +94,7 @@ void * list_lookup(struct list *l, const char *name)
|
|||
int list_contains(struct list *l, void *p)
|
||||
{
|
||||
int cmp_helper(const void *a, const void *b) {
|
||||
return a == b;
|
||||
return a == b ? 0 : 1;
|
||||
}
|
||||
|
||||
return list_count(l, cmp_helper, p);
|
||||
|
@ -103,7 +107,7 @@ int list_count(struct list *l, cmp_cb_t cmp, void *ctx)
|
|||
pthread_mutex_lock(&l->lock);
|
||||
|
||||
list_foreach(void *e, l) {
|
||||
if (!cmp(e, ctx))
|
||||
if (cmp(e, ctx) == 0)
|
||||
c++;
|
||||
}
|
||||
|
||||
|
|
|
@ -170,7 +170,7 @@ int main(int argc, char *argv[])
|
|||
info("Starting nodes");
|
||||
list_foreach(struct node *n, &nodes) { INDENT
|
||||
int used_by_path(struct path *p, struct node *n) {
|
||||
return (p->in == n) || list_contains(&p->destinations, n);
|
||||
return (p->in == n) || list_contains(&p->destinations, n) ? 0 : 1;
|
||||
}
|
||||
|
||||
int refs = list_count(&paths, (cmp_cb_t) used_by_path, n);
|
||||
|
|
Loading…
Add table
Reference in a new issue