2 * Copyright (c) 2009 Joseph Koshy
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 ** Miscellanous definitions needed by multiple components.
37 #define NULL ((void *) 0)
41 #define offsetof(T, M) ((int) &((T*) 0) -> M)
45 * Supply macros missing from <sys/queue.h>
48 #ifndef STAILQ_FOREACH_SAFE
49 #define STAILQ_FOREACH_SAFE(var, head, field, tvar) \
50 for ((var) = STAILQ_FIRST((head)); \
51 (var) && ((tvar) = STAILQ_NEXT((var), field), 1); \
56 #define STAILQ_LAST(head, type, field) \
57 (STAILQ_EMPTY((head)) ? \
59 ((struct type *)(void *) \
60 ((char *)((head)->stqh_last) - offsetof(struct type, field))))
63 #ifndef TAILQ_FOREACH_SAFE
64 #define TAILQ_FOREACH_SAFE(var, head, field, tvar) \
65 for ((var) = TAILQ_FIRST((head)); \
66 (var) && ((tvar) = TAILQ_NEXT((var), field), 1); \
76 #if defined(__FreeBSD__)
77 #define ELFTC_VCSID(ID) __FBSDID(ID)
80 #if defined(__linux__) || defined(__GNU__) || defined(__GLIBC__)
81 #define ELFTC_VCSID(ID) /**/
84 #if defined(__NetBSD__)
85 #define ELFTC_VCSID(ID) __RCSID(ID)
88 #endif /* ELFTC_VCSID */
91 * Provide an equivalent for getprogname(3).
94 #ifndef ELFTC_GETPROGNAME
96 #if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__minix)
100 #define ELFTC_GETPROGNAME() getprogname()
102 #endif /* defined(__FreeBSD__) || defined(__NetBSD__) || defined(__minix) */
105 #if defined(__linux__)
108 * GLIBC based systems have a global 'char *' pointer referencing
109 * the executable's name.
111 extern const char *program_invocation_short_name
;
113 #define ELFTC_GETPROGNAME() program_invocation_short_name
115 #endif /* __linux__ */
117 #endif /* ELFTC_GETPROGNAME */
120 ** Per-OS configuration.
123 #if defined(__linux__)
127 #define ELFTC_BYTE_ORDER __BYTE_ORDER
128 #define ELFTC_BYTE_ORDER_LITTLE_ENDIAN __LITTLE_ENDIAN
129 #define ELFTC_BYTE_ORDER_BIG_ENDIAN __BIG_ENDIAN
132 * Debian GNU/Linux is missing strmode(3).
134 #define ELFTC_HAVE_STRMODE 0
136 /* Whether we need to supply {be,le}32dec. */
137 #define ELFTC_NEED_BYTEORDER_EXTENSIONS 1
139 #define roundup2 roundup
141 #endif /* __linux__ */
144 #if defined(__FreeBSD__)
146 #include <sys/endian.h>
148 #define ELFTC_BYTE_ORDER _BYTE_ORDER
149 #define ELFTC_BYTE_ORDER_LITTLE_ENDIAN _LITTLE_ENDIAN
150 #define ELFTC_BYTE_ORDER_BIG_ENDIAN _BIG_ENDIAN
152 #define ELFTC_HAVE_STRMODE 1
153 #endif /* __FreeBSD__ */
156 #if defined(__NetBSD__) || defined(__minix)
158 #include <sys/endian.h>
160 #define ELFTC_BYTE_ORDER _BYTE_ORDER
161 #define ELFTC_BYTE_ORDER_LITTLE_ENDIAN _LITTLE_ENDIAN
162 #define ELFTC_BYTE_ORDER_BIG_ENDIAN _BIG_ENDIAN
164 #define ELFTC_HAVE_STRMODE 1
165 #endif /* __NetBSD __ || __minix */
167 #endif /* _ELFTC_H */