1 /* 2 * Copyright © 2008-2011 Kristian Høgsberg 3 * Copyright © 2011 Intel Corporation 4 * Copyright © 2013-2015 Red Hat, Inc. 5 * 6 * Permission is hereby granted, free of charge, to any person obtaining a 7 * copy of this software and associated documentation files (the "Software"), 8 * to deal in the Software without restriction, including without limitation 9 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 10 * and/or sell copies of the Software, and to permit persons to whom the 11 * Software is furnished to do so, subject to the following conditions: 12 * 13 * The above copyright notice and this permission notice (including the next 14 * paragraph) shall be included in all copies or substantial portions of the 15 * Software. 16 * 17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 22 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 23 * DEALINGS IN THE SOFTWARE. 24 */ 25 26 #pragma once 27 28 #include "config.h" 29 30 #include <stdbool.h> 31 #include <stddef.h> 32 33 /* 34 * This list data structure is a verbatim copy from wayland-util.h from the 35 * Wayland project; except that wl_ prefix has been removed. 36 */ 37 38 struct list { 39 struct list *prev; 40 struct list *next; 41 }; 42 43 void list_init(struct list *list); 44 void list_insert(struct list *list, struct list *elm); 45 void list_append(struct list *list, struct list *elm); 46 void list_remove(struct list *elm); 47 bool list_empty(const struct list *list); 48 49 #define container_of(ptr, type, member) \ 50 (__typeof__(type) *)((char *)(ptr) - \ 51 offsetof(__typeof__(type), member)) 52 53 #define list_first_entry(head, pos, member) \ 54 container_of((head)->next, __typeof__(*pos), member) 55 56 #define list_for_each(pos, head, member) \ 57 for (pos = 0, pos = list_first_entry(head, pos, member); \ 58 &pos->member != (head); \ 59 pos = list_first_entry(&pos->member, pos, member)) 60 61 #define list_for_each_safe(pos, tmp, head, member) \ 62 for (pos = 0, tmp = 0, \ 63 pos = list_first_entry(head, pos, member), \ 64 tmp = list_first_entry(&pos->member, tmp, member); \ 65 &pos->member != (head); \ 66 pos = tmp, \ 67 tmp = list_first_entry(&pos->member, tmp, member)) 68