vaseboot/include/VasEBoot/list.h

89 lines
3.5 KiB
C

/* list.h - header for VasEBoot list */
/*
* VAS_EBOOT -- GRand Unified Bootloader
* Copyright (C) 2009 Free Software Foundation, Inc.
*
* VAS_EBOOT is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* VAS_EBOOT is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with VAS_EBOOT. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef VAS_EBOOT_LIST_HEADER
#define VAS_EBOOT_LIST_HEADER 1
#include <VasEBoot/symbol.h>
#include <VasEBoot/err.h>
#include <VasEBoot/compiler.h>
struct VasEBoot_list
{
struct VasEBoot_list *next;
struct VasEBoot_list **prev;
};
typedef struct VasEBoot_list *VasEBoot_list_t;
void EXPORT_FUNC(VasEBoot_list_push) (VasEBoot_list_t *head, VasEBoot_list_t item);
void EXPORT_FUNC(VasEBoot_list_remove) (VasEBoot_list_t item);
#define FOR_LIST_ELEMENTS(var, list) for ((var) = (list); (var); (var) = (var)->next)
#define FOR_LIST_ELEMENTS_NEXT(var, list) for ((var) = (var)->next; (var); (var) = (var)->next)
#define FOR_LIST_ELEMENTS_SAFE(var, nxt, list) for ((var) = (list), (nxt) = ((var) ? (var)->next : 0); (var); (var) = (nxt), ((nxt) = (var) ? (var)->next : 0))
static inline void *
VasEBoot_bad_type_cast_real (int line, const char *file)
VAS_EBOOT_ATTRIBUTE_ERROR ("bad type cast between incompatible VasEBoot types");
static inline void *
VasEBoot_bad_type_cast_real (int line, const char *file)
{
VasEBoot_fatal ("error:%s:%u: bad type cast between incompatible VasEBoot types",
file, line);
}
#define VasEBoot_bad_type_cast() VasEBoot_bad_type_cast_real(__LINE__, VAS_EBOOT_FILE)
#define VAS_EBOOT_FIELD_MATCH(ptr, type, field) \
((char *) &(ptr)->field == (char *) &((type) (ptr))->field)
#define VAS_EBOOT_AS_LIST(ptr) \
(VAS_EBOOT_FIELD_MATCH (ptr, VasEBoot_list_t, next) && VAS_EBOOT_FIELD_MATCH (ptr, VasEBoot_list_t, prev) ? \
(VasEBoot_list_t) ptr : (VasEBoot_list_t) VasEBoot_bad_type_cast ())
#define VAS_EBOOT_AS_LIST_P(pptr) \
(VAS_EBOOT_FIELD_MATCH (*pptr, VasEBoot_list_t, next) && VAS_EBOOT_FIELD_MATCH (*pptr, VasEBoot_list_t, prev) ? \
(VasEBoot_list_t *) (void *) pptr : (VasEBoot_list_t *) VasEBoot_bad_type_cast ())
struct VasEBoot_named_list
{
struct VasEBoot_named_list *next;
struct VasEBoot_named_list **prev;
char *name;
};
typedef struct VasEBoot_named_list *VasEBoot_named_list_t;
void * EXPORT_FUNC(VasEBoot_named_list_find) (VasEBoot_named_list_t head,
const char *name);
#define VAS_EBOOT_AS_NAMED_LIST(ptr) \
((VAS_EBOOT_FIELD_MATCH (ptr, VasEBoot_named_list_t, next) \
&& VAS_EBOOT_FIELD_MATCH (ptr, VasEBoot_named_list_t, prev) \
&& VAS_EBOOT_FIELD_MATCH (ptr, VasEBoot_named_list_t, name))? \
(VasEBoot_named_list_t) ptr : (VasEBoot_named_list_t) VasEBoot_bad_type_cast ())
#define VAS_EBOOT_AS_NAMED_LIST_P(pptr) \
((VAS_EBOOT_FIELD_MATCH (*pptr, VasEBoot_named_list_t, next) \
&& VAS_EBOOT_FIELD_MATCH (*pptr, VasEBoot_named_list_t, prev) \
&& VAS_EBOOT_FIELD_MATCH (*pptr, VasEBoot_named_list_t, name))? \
(VasEBoot_named_list_t *) (void *) pptr : (VasEBoot_named_list_t *) VasEBoot_bad_type_cast ())
#endif /* ! VAS_EBOOT_LIST_HEADER */