/*1Simple DirectMedia Layer2Copyright (C) 1997-2025 Sam Lantinga <[email protected]>34This software is provided 'as-is', without any express or implied5warranty. In no event will the authors be held liable for any damages6arising from the use of this software.78Permission is granted to anyone to use this software for any purpose,9including commercial applications, and to alter it and redistribute it10freely, subject to the following restrictions:11121. The origin of this software must not be misrepresented; you must not13claim that you wrote the original software. If you use this software14in a product, an acknowledgment in the product documentation would be15appreciated but is not required.162. Altered source versions must be plainly marked as such, and must not be17misrepresented as being the original software.183. This notice may not be removed or altered from any source distribution.19*/20#include "SDL_internal.h"2122#include "./SDL_list.h"2324// Push25bool SDL_ListAdd(SDL_ListNode **head, void *ent)26{27SDL_ListNode *node = (SDL_ListNode *)SDL_malloc(sizeof(*node));2829if (!node) {30return false;31}3233node->entry = ent;34node->next = *head;35*head = node;36return true;37}3839// Pop from end as a FIFO (if add with SDL_ListAdd)40void SDL_ListPop(SDL_ListNode **head, void **ent)41{42SDL_ListNode **ptr = head;4344// Invalid or empty45if (!head || !*head) {46return;47}4849while ((*ptr)->next) {50ptr = &(*ptr)->next;51}5253if (ent) {54*ent = (*ptr)->entry;55}5657SDL_free(*ptr);58*ptr = NULL;59}6061void SDL_ListRemove(SDL_ListNode **head, void *ent)62{63SDL_ListNode **ptr = head;6465while (*ptr) {66if ((*ptr)->entry == ent) {67SDL_ListNode *tmp = *ptr;68*ptr = (*ptr)->next;69SDL_free(tmp);70return;71}72ptr = &(*ptr)->next;73}74}7576void SDL_ListClear(SDL_ListNode **head)77{78SDL_ListNode *l = *head;79*head = NULL;80while (l) {81SDL_ListNode *tmp = l;82l = l->next;83SDL_free(tmp);84}85}868788