int s_list_remove()

in common/src/s_list.c [105:150]


int s_list_remove(PS_LIST_ENTRY list_head, PS_LIST_ENTRY list_entry)
{
    int result;
    if (
    /* Codes_SRS_S_LIST_07_011: [ If list_head is NULL, s_list_remove shall fail and a non-zero value. ]*/
    (list_head == NULL) ||
    /* Codes_SRS_S_LIST_07_012: [ If list_entry is NULL, s_list_remove shall fail and a non-zero value. ]*/
    (list_entry == NULL))
    {
        LogError("Invalid arguments (list_head=%p, list_entry=%p)", list_head, list_entry);
        result = MU_FAILURE;
    }
    else
    {
        PS_LIST_ENTRY prev_item = NULL;
        PS_LIST_ENTRY current_item = list_head->next;
        while (current_item != NULL)
        {
            if (current_item == list_entry)
            {
                break;
            }
            prev_item = current_item;
            current_item = current_item->next;
        }
        if (current_item == NULL)
        {
            /* Codes_SRS_S_LIST_07_014: [ If the entry list_entry is not found in the list, then s_list_remove shall fail and a non-zero value. ]*/
            result = MU_FAILURE;
        }
        else
        {
            /* Codes_SRS_S_LIST_07_013: [ s_list_remove shall remove a list entry from the list and return zero on success. ]*/
            if (prev_item != NULL)
            {
                prev_item->next = current_item->next;
            }
            else
            {
                list_head->next = list_head->next->next;
            }
            result = 0;
        }
    }
    return result;
}