Skip to content

Commit 5aa6f25

Browse files
committed
Implement q_new function
The function q_new allocates memory for an empty queue and initializes it. If memory allocation fails, the function will return NULL, otherwise, return the head of the empty queue. Change-Id: I4aa0bb5cbe20738ba435a2ecefbf352c953cb156
1 parent 1d68fae commit 5aa6f25

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

queue.c

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

1924
/* Free all storage used by queue */

0 commit comments

Comments
 (0)