Skip to content

Commit 6bbdec7

Browse files
committed
Fix q_remove_head
Previously, q_remove_head always returned NULL without modifying the list. Now, it properly removes the first element, copies its value to the provided buffer, and returns the removed element. This ensures correct queue behavior. Change-Id: I32dd35453dac36972dce69c825703125bb54b27d
1 parent e0515ae commit 6bbdec7

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

queue.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,14 @@ bool q_insert_tail(struct list_head *head, char *s)
7070
/* Remove an element from head of queue */
7171
element_t *q_remove_head(struct list_head *head, char *sp, size_t bufsize)
7272
{
73-
return NULL;
73+
if (!head || list_empty(head))
74+
return NULL;
75+
struct list_head *rm_node = head->next;
76+
element_t *rm_elem = list_entry(rm_node, element_t, list);
77+
bufsize = strlen(rm_elem->value) + 1;
78+
strlcpy(sp, rm_elem->value, bufsize);
79+
list_del(rm_node);
80+
return rm_elem;
7481
}
7582

7683
/* Remove an element from tail of queue */

0 commit comments

Comments
 (0)