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,27 +51,25 @@ 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)
{
if (prev)
prev->next = listener->next;
else
listener_list = NULL;
free(listener);
return 0;
}
break;
prev = listener;
listener = listener->next;
}
return -1;
if (!listener)
return 0;
if (prev)
prev->next = listener->next;
else
listener_list = NULL;
free(listener);
return 0;
}
int