Skip to content

Commit fc2f58c

Browse files
committed
Implement q_new
Using INIT_LIST_HEAD to allocate memory for a new queue. If allocated FAILED, it will return NULL. Change-Id: I3729cc166f4b5f9ba74f94a558a58fdf4c15cec4
1 parent bb50402 commit fc2f58c

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 *new = malloc(sizeof(struct list_head));
17+
if (!new)
18+
return NULL;
19+
INIT_LIST_HEAD(new);
20+
21+
return new;
1722
}
1823

1924
/* Free all storage used by queue */

0 commit comments

Comments
 (0)