Skip to content

Commit bda78c1

Browse files
committed
Implement q_new to create an empty queue
Allocate memory for a new queue and initialize its list head. Return NULL if memory allocation fails. Change-Id: I31f38aa864e5587528bfeb0f3e09cd6ad4056402
1 parent a41ccb4 commit bda78c1

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

queue.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@
1313
/* Create an empty queue */
1414
struct list_head *q_new()
1515
{
16-
return NULL;
16+
struct list_head *head = malloc(sizeof(struct list_head));
17+
if (!head)
18+
return NULL;
19+
INIT_LIST_HEAD(head);
20+
return head;
1721
}
1822

1923
/* Free all storage used by queue */

0 commit comments

Comments
 (0)