1 // Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved. 2 // 3 // This program is free software; you can redistribute it and/or modify 4 // it under the terms of the GNU General Public License, version 2.0, as 5 // published by the Free Software Foundation. 6 // 7 // This program is also distributed with certain software (including 8 // but not limited to OpenSSL) that is licensed under separate terms, 9 // as designated in a particular file or component or in included license 10 // documentation. The authors of MySQL hereby grant you an 11 // additional permission to link the program and your derivative works 12 // with the separately licensed software that they have included with 13 // MySQL. 14 // 15 // Without limiting anything contained in the foregoing, this file, 16 // which is part of MySQL Server, is also subject to the 17 // Universal FOSS Exception, version 1.0, a copy of which can be found at 18 // http://oss.oracle.com/licenses/universal-foss-exception. 19 // 20 // This program is distributed in the hope that it will be useful, but 21 // WITHOUT ANY WARRANTY; without even the implied warranty of 22 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 23 // See the GNU General Public License, version 2.0, for more details. 24 // 25 // You should have received a copy of the GNU General Public License 26 // along with this program; if not, write to the Free Software Foundation, Inc., 27 // 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 28 29 #ifndef _list_h_ 30 #define _list_h_ 31 32 /** 33 @file include/my_list.h 34 */ 35 36 /* 37 NOTE: This file should really include mysql/service_mysql_alloc.h 38 (due to the my_free() call in list_pop), but that is not acceptable 39 in client code, so it has been kept out. 40 */ 41 42 typedef struct LIST { 43 #if defined(__cplusplus) && __cplusplus >= 201103L 44 struct LIST *prev{nullptr}, *next{nullptr}; 45 void *data{nullptr}; 46 #else 47 struct LIST *prev, *next; 48 void *data; 49 #endif 50 } LIST; 51 52 typedef int (*list_walk_action)(void *, void *); 53 54 extern LIST *list_add(LIST *root, LIST *element); 55 extern LIST *list_delete(LIST *root, LIST *element); 56 extern LIST *list_cons(void *data, LIST *root); 57 extern LIST *list_reverse(LIST *root); 58 extern void list_free(LIST *root, unsigned int free_data); 59 extern unsigned int list_length(LIST *); 60 extern int list_walk(LIST *, list_walk_action action, unsigned char *argument); 61 62 #define list_rest(a) ((a)->next) 63 #define list_push(a, b) (a) = list_cons((b), (a)) 64 #define list_pop(A) \ 65 { \ 66 LIST *old = (A); \ 67 (A) = list_delete(old, old); \ 68 my_free(old); \ 69 } 70 71 #endif 72