Skip to content

Commit ddb885b

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

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
@@ -83,7 +83,14 @@ element_t *q_remove_head(struct list_head *head, char *sp, size_t bufsize)
8383
/* Remove an element from tail of queue */
8484
element_t *q_remove_tail(struct list_head *head, char *sp, size_t bufsize)
8585
{
86-
return NULL;
86+
if (!head || list_empty(head))
87+
return NULL;
88+
struct list_head *rm_node = head->prev;
89+
element_t *rm_elem = list_entry(rm_node, element_t, list);
90+
bufsize = strlen(rm_elem->value) + 1;
91+
strlcpy(sp, rm_elem->value, bufsize);
92+
list_del(rm_node);
93+
return rm_elem;
8794
}
8895

8996
/* Return number of elements in queue */

0 commit comments

Comments
 (0)