1a46c0ec8Sopenharmony_ci/* 2a46c0ec8Sopenharmony_ci * Copyright © 2008-2011 Kristian Høgsberg 3a46c0ec8Sopenharmony_ci * Copyright © 2011 Intel Corporation 4a46c0ec8Sopenharmony_ci * Copyright © 2013-2015 Red Hat, Inc. 5a46c0ec8Sopenharmony_ci * 6a46c0ec8Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 7a46c0ec8Sopenharmony_ci * copy of this software and associated documentation files (the "Software"), 8a46c0ec8Sopenharmony_ci * to deal in the Software without restriction, including without limitation 9a46c0ec8Sopenharmony_ci * the rights to use, copy, modify, merge, publish, distribute, sublicense, 10a46c0ec8Sopenharmony_ci * and/or sell copies of the Software, and to permit persons to whom the 11a46c0ec8Sopenharmony_ci * Software is furnished to do so, subject to the following conditions: 12a46c0ec8Sopenharmony_ci * 13a46c0ec8Sopenharmony_ci * The above copyright notice and this permission notice (including the next 14a46c0ec8Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the 15a46c0ec8Sopenharmony_ci * Software. 16a46c0ec8Sopenharmony_ci * 17a46c0ec8Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18a46c0ec8Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19a46c0ec8Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 20a46c0ec8Sopenharmony_ci * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21a46c0ec8Sopenharmony_ci * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22a46c0ec8Sopenharmony_ci * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 23a46c0ec8Sopenharmony_ci * DEALINGS IN THE SOFTWARE. 24a46c0ec8Sopenharmony_ci */ 25a46c0ec8Sopenharmony_ci 26a46c0ec8Sopenharmony_ci#include "config.h" 27a46c0ec8Sopenharmony_ci 28a46c0ec8Sopenharmony_ci#include <assert.h> 29a46c0ec8Sopenharmony_ci#include <stddef.h> 30a46c0ec8Sopenharmony_ci#include <stdbool.h> 31a46c0ec8Sopenharmony_ci 32a46c0ec8Sopenharmony_ci#include "util-list.h" 33a46c0ec8Sopenharmony_ci 34a46c0ec8Sopenharmony_civoid 35a46c0ec8Sopenharmony_cilist_init(struct list *list) 36a46c0ec8Sopenharmony_ci{ 37a46c0ec8Sopenharmony_ci list->prev = list; 38a46c0ec8Sopenharmony_ci list->next = list; 39a46c0ec8Sopenharmony_ci} 40a46c0ec8Sopenharmony_ci 41a46c0ec8Sopenharmony_civoid 42a46c0ec8Sopenharmony_cilist_insert(struct list *list, struct list *elm) 43a46c0ec8Sopenharmony_ci{ 44a46c0ec8Sopenharmony_ci assert((list->next != NULL && list->prev != NULL) || 45a46c0ec8Sopenharmony_ci !"list->next|prev is NULL, possibly missing list_init()"); 46a46c0ec8Sopenharmony_ci assert(((elm->next == NULL && elm->prev == NULL) || list_empty(elm)) || 47a46c0ec8Sopenharmony_ci !"elm->next|prev is not NULL, list node used twice?"); 48a46c0ec8Sopenharmony_ci 49a46c0ec8Sopenharmony_ci elm->prev = list; 50a46c0ec8Sopenharmony_ci elm->next = list->next; 51a46c0ec8Sopenharmony_ci list->next = elm; 52a46c0ec8Sopenharmony_ci elm->next->prev = elm; 53a46c0ec8Sopenharmony_ci} 54a46c0ec8Sopenharmony_ci 55a46c0ec8Sopenharmony_civoid 56a46c0ec8Sopenharmony_cilist_append(struct list *list, struct list *elm) 57a46c0ec8Sopenharmony_ci{ 58a46c0ec8Sopenharmony_ci assert((list->next != NULL && list->prev != NULL) || 59a46c0ec8Sopenharmony_ci !"list->next|prev is NULL, possibly missing list_init()"); 60a46c0ec8Sopenharmony_ci assert(((elm->next == NULL && elm->prev == NULL) || list_empty(elm)) || 61a46c0ec8Sopenharmony_ci !"elm->next|prev is not NULL, list node used twice?"); 62a46c0ec8Sopenharmony_ci 63a46c0ec8Sopenharmony_ci elm->next = list; 64a46c0ec8Sopenharmony_ci elm->prev = list->prev; 65a46c0ec8Sopenharmony_ci list->prev = elm; 66a46c0ec8Sopenharmony_ci elm->prev->next = elm; 67a46c0ec8Sopenharmony_ci} 68a46c0ec8Sopenharmony_ci 69a46c0ec8Sopenharmony_civoid 70a46c0ec8Sopenharmony_cilist_remove(struct list *elm) 71a46c0ec8Sopenharmony_ci{ 72a46c0ec8Sopenharmony_ci assert((elm->next != NULL && elm->prev != NULL) || 73a46c0ec8Sopenharmony_ci !"list->next|prev is NULL, possibly missing list_init()"); 74a46c0ec8Sopenharmony_ci 75a46c0ec8Sopenharmony_ci elm->prev->next = elm->next; 76a46c0ec8Sopenharmony_ci elm->next->prev = elm->prev; 77a46c0ec8Sopenharmony_ci elm->next = NULL; 78a46c0ec8Sopenharmony_ci elm->prev = NULL; 79a46c0ec8Sopenharmony_ci} 80a46c0ec8Sopenharmony_ci 81a46c0ec8Sopenharmony_cibool 82a46c0ec8Sopenharmony_cilist_empty(const struct list *list) 83a46c0ec8Sopenharmony_ci{ 84a46c0ec8Sopenharmony_ci assert((list->next != NULL && list->prev != NULL) || 85a46c0ec8Sopenharmony_ci !"list->next|prev is NULL, possibly missing list_init()"); 86a46c0ec8Sopenharmony_ci 87a46c0ec8Sopenharmony_ci return list->next == list; 88a46c0ec8Sopenharmony_ci} 89