ruby/yarp/util/yp_list.c
Jemma Issroff cc7f765f2c [Feature #19741] Sync all files in yarp
This commit is the initial sync of all files from ruby/yarp
into ruby/ruby. Notably, it does the following:

* Sync all ruby/yarp/lib/ files to ruby/ruby/lib/yarp
* Sync all ruby/yarp/src/ files to ruby/ruby/yarp/
* Sync all ruby/yarp/test/ files to ruby/ruby/test/yarp
2023-06-21 11:25:39 -07:00

37 lines
826 B
C

#include "yarp/util/yp_list.h"
// Initializes a new list.
YP_EXPORTED_FUNCTION void
yp_list_init(yp_list_t *list) {
*list = (yp_list_t) { .head = NULL, .tail = NULL };
}
// Returns true if the given list is empty.
YP_EXPORTED_FUNCTION bool
yp_list_empty_p(yp_list_t *list) {
return list->head == NULL;
}
// Append a node to the given list.
void
yp_list_append(yp_list_t *list, yp_list_node_t *node) {
if (list->head == NULL) {
list->head = node;
} else {
list->tail->next = node;
}
list->tail = node;
}
// Deallocate the internal state of the given list.
YP_EXPORTED_FUNCTION void
yp_list_free(yp_list_t *list) {
yp_list_node_t *node = list->head;
yp_list_node_t *next;
while (node != NULL) {
next = node->next;
free(node);
node = next;
}
}