refactor use for loop to remove item from linked list

This commit is contained in:
chme 2015-05-13 11:37:09 +02:00
parent 3886ec6638
commit baffe49887

View File

@ -51,13 +51,18 @@ listener_remove(notify notify_cb)
struct listener *listener;
struct listener *prev;
listener = listener_list;
prev = NULL;
while (listener)
for (listener = listener_list; listener; listener = listener->next)
{
if (listener->notify_cb == notify_cb)
{
break;
prev = listener;
}
if (!listener)
return 0;
if (prev)
prev->next = listener->next;
else
@ -65,13 +70,6 @@ listener_remove(notify notify_cb)
free(listener);
return 0;
}
prev = listener;
listener = listener->next;
}
return -1;
}
int