queue.c
/*
 * Attempt to remove element from head of queue.
 * Return target element.
 * Return NULL if queue is NULL or empty.
 * If sp is non-NULL and an element is removed, copy the removed string to *sp
 * (up to a maximum of bufsize-1 characters, plus a null terminator.)
 *
 * NOTE: "remove" is different from "delete"
 * The space used by the list element and the string should not be freed.
 * The only thing "remove" need to do is unlink it.
 *
 * REF:
 * https://english.stackexchange.com/questions/52508/difference-between-delete-and-remove
 */
Attempt to remove element from head of queue.
Return target element.
Return NULL if queue is NULL or empty.
If sp is non-NULL and an element is removed, copy the removed string to *sp
(up to a maximum of bufsize-1 characters, plus a null terminator.)

"remove" is different from "delete"
The space used by the list element and the string should not be freed.
The only thing "remove" need to do is unlink it.


Attempt to remove element from head of queue . Return target element . Return NULL if queue is NULL or empty . If sp is non - NULL and an element is removed copy the removed string to * sp ( up to a maximum of bufsize - 1 characters plus a null terminator . ) " remove " is different from " delete " The space used by the list element and the string should not be freed . The only thing " remove " need to do is unlink it .
element_t *q_remove_head(struct list_head *head, char *sp, size_t bufsize)
{
    if (!head || head->next == head)
        return NULL;
    else {
        struct list_head *del = head->next;
        list_del_init(head->next);
        element_t *del_ele = list_entry(del, element_t, list);
        if (sp) {
            strncpy(sp, del_ele->value, bufsize - 1);
            *(sp + bufsize - 1) = '\0';
        }
        return del_ele;
    }
}
element_t * q_remove_head ( struct list_head * head , char * sp , size_t bufsize ) { if ( ! head || head -> next == head ) return NULL ; else { struct list_head * del = head -> next ; list_del_init ( head -> next ) ; element_t * del_ele = list_entry ( del , element_t , list ) ; if ( sp ) { strncpy ( sp , del_ele -> value , bufsize - 1 ) ; * ( sp + bufsize - 1 ) = ' \0 ' ; } return del_ele ; } }
Attempt to remove element from head of queue.
Attempt to remove element from head of queue .