Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:54:01

0001 /*
0002  * Copyright © 2004-2006, 2009-2011 Guillem Jover <guillem@hadrons.org>
0003  *
0004  * Redistribution and use in source and binary forms, with or without
0005  * modification, are permitted provided that the following conditions
0006  * are met:
0007  * 1. Redistributions of source code must retain the above copyright
0008  *    notice, this list of conditions and the following disclaimer.
0009  * 2. Redistributions in binary form must reproduce the above copyright
0010  *    notice, this list of conditions and the following disclaimer in the
0011  *    documentation and/or other materials provided with the distribution.
0012  * 3. The name of the author may not be used to endorse or promote products
0013  *    derived from this software without specific prior written permission.
0014  *
0015  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
0016  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
0017  * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
0018  * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
0019  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
0020  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
0021  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
0022  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
0023  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
0024  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
0025  */
0026 
0027 #ifndef __has_include
0028 #define __has_include(x) 1
0029 #endif
0030 #ifndef __has_include_next
0031 #define __has_include_next(x) 1
0032 #endif
0033 #ifndef __has_attribute
0034 #define __has_attribute(x) 0
0035 #endif
0036 /* Clang expands this to 1 if an identifier is *not* reserved. */
0037 #ifndef __is_identifier
0038 #define __is_identifier(x) 1
0039 #endif
0040 #ifndef __has_builtin
0041 #define __has_builtin(x) !__is_identifier(x)
0042 #endif
0043 
0044 #ifdef LIBBSD_OVERLAY
0045 /*
0046  * Some libc implementations do not have a <sys/cdefs.h>, in particular
0047  * musl, try to handle this gracefully.
0048  */
0049 #if __has_include_next(<sys/cdefs.h>)
0050 #include_next <sys/cdefs.h>
0051 #endif
0052 #else
0053 #if __has_include(<sys/cdefs.h>)
0054 #include <sys/cdefs.h>
0055 #endif
0056 #endif
0057 
0058 #ifndef LIBBSD_SYS_CDEFS_H
0059 #define LIBBSD_SYS_CDEFS_H
0060 
0061 #ifndef __BEGIN_DECLS
0062 #ifdef __cplusplus
0063 #define __BEGIN_DECLS   extern "C" {
0064 #define __END_DECLS }
0065 #else
0066 #define __BEGIN_DECLS
0067 #define __END_DECLS
0068 #endif
0069 #endif
0070 
0071 /*
0072  * On non-glibc based systems, we cannot unconditionally use the
0073  * __GLIBC_PREREQ macro as it gets expanded before evaluation.
0074  */
0075 #ifndef __GLIBC_PREREQ
0076 #define __GLIBC_PREREQ(maj, min) 0
0077 #endif
0078 
0079 /*
0080  * Some kFreeBSD headers expect those macros to be set for sanity checks.
0081  */
0082 #ifndef _SYS_CDEFS_H_
0083 #define _SYS_CDEFS_H_
0084 #endif
0085 #ifndef _SYS_CDEFS_H
0086 #define _SYS_CDEFS_H
0087 #endif
0088 
0089 /* Define the ABI for the current system. */
0090 #define LIBBSD_SYS_TIME_BITS 64
0091 #define LIBBSD_SYS_HAS_TIME64 1
0092 
0093 #define LIBBSD_CONCAT(x, y) x ## y
0094 #define LIBBSD_STRING(x)    #x
0095 
0096 #ifdef __GNUC__
0097 #define LIBBSD_GCC_VERSION (__GNUC__ << 8 | __GNUC_MINOR__)
0098 #else
0099 #define LIBBSD_GCC_VERSION 0
0100 #endif
0101 
0102 #if LIBBSD_GCC_VERSION >= 0x0405 || __has_attribute(__deprecated__)
0103 #define LIBBSD_DEPRECATED(x) __attribute__((__deprecated__(x)))
0104 #elif LIBBSD_GCC_VERSION >= 0x0301
0105 #define LIBBSD_DEPRECATED(x) __attribute__((__deprecated__))
0106 #else
0107 #define LIBBSD_DEPRECATED(x)
0108 #endif
0109 
0110 #if LIBBSD_GCC_VERSION >= 0x0200 || defined(__clang__)
0111 #define LIBBSD_REDIRECT(name, proto, alias) name proto __asm__(LIBBSD_ASMNAME(#alias))
0112 #endif
0113 #define LIBBSD_ASMNAME(cname) LIBBSD_ASMNAME_PREFIX(__USER_LABEL_PREFIX__, cname)
0114 #define LIBBSD_ASMNAME_PREFIX(prefix, cname) LIBBSD_STRING(prefix) cname
0115 
0116 #ifndef __dead2
0117 # if LIBBSD_GCC_VERSION >= 0x0207 || __has_attribute(__noreturn__)
0118 #  define __dead2 __attribute__((__noreturn__))
0119 # else
0120 #  define __dead2
0121 # endif
0122 #endif
0123 
0124 #ifndef __pure2
0125 # if LIBBSD_GCC_VERSION >= 0x0207 || __has_attribute(__const__)
0126 #  define __pure2 __attribute__((__const__))
0127 # else
0128 #  define __pure2
0129 # endif
0130 #endif
0131 
0132 #ifndef __packed
0133 # if LIBBSD_GCC_VERSION >= 0x0207 || __has_attribute(__packed__)
0134 #  define __packed __attribute__((__packed__))
0135 # else
0136 #  define __packed
0137 # endif
0138 #endif
0139 
0140 #ifndef __aligned
0141 # if LIBBSD_GCC_VERSION >= 0x0207 || __has_attribute(__aligned__)
0142 #  define __aligned(x) __attribute__((__aligned__(x)))
0143 # else
0144 #  define __aligned(x)
0145 # endif
0146 #endif
0147 
0148 /* Linux headers define a struct with a member names __unused.
0149  * Debian bugs: #522773 (linux), #522774 (libc).
0150  * Disable for now. */
0151 #if 0
0152 #ifndef __unused
0153 # if LIBBSD_GCC_VERSION >= 0x0300
0154 #  define __unused __attribute__((__unused__))
0155 # else
0156 #  define __unused
0157 # endif
0158 #endif
0159 #endif
0160 
0161 #ifndef __printflike
0162 # if LIBBSD_GCC_VERSION >= 0x0300 || __has_attribute(__format__)
0163 #  define __printflike(x, y) __attribute((__format__(__printf__, (x), (y))))
0164 # else
0165 #  define __printflike(x, y)
0166 # endif
0167 #endif
0168 
0169 #ifndef __nonnull
0170 # if LIBBSD_GCC_VERSION >= 0x0302 || __has_attribute(__nonnull__)
0171 #  define __nonnull(x) __attribute__((__nonnull__(x)))
0172 # else
0173 #  define __nonnull(x)
0174 # endif
0175 #endif
0176 
0177 #ifndef __bounded__
0178 # define __bounded__(x, y, z)
0179 #endif
0180 
0181 /*
0182  * Return the number of elements in a statically-allocated array,
0183  * __x.
0184  */
0185 #define __arraycount(__x)   (sizeof(__x) / sizeof(__x[0]))
0186 
0187 /*
0188  * We define this here since <stddef.h>, <sys/queue.h>, and <sys/types.h>
0189  * require it.
0190  */
0191 #ifndef __offsetof
0192 # if LIBBSD_GCC_VERSION >= 0x0401 || __has_builtin(__builtin_offsetof)
0193 #  define __offsetof(type, field)   __builtin_offsetof(type, field)
0194 # else
0195 #  ifndef __cplusplus
0196 #   define __offsetof(type, field) \
0197            ((size_t)(uintptr_t)((const volatile void *)&((type *)0)->field))
0198 #  else
0199 #   define __offsetof(type, field) \
0200     (__offsetof__ (reinterpret_cast <size_t> \
0201                    (&reinterpret_cast <const volatile char &> \
0202                     (static_cast<type *> (0)->field))))
0203 #  endif
0204 # endif
0205 #endif
0206 
0207 #define __rangeof(type, start, end) \
0208         (__offsetof(type, end) - __offsetof(type, start))
0209 
0210 /*
0211  * Given the pointer x to the member m of the struct s, return
0212  * a pointer to the containing structure.  When using GCC, we first
0213  * assign pointer x to a local variable, to check that its type is
0214  * compatible with member m.
0215  */
0216 #ifndef __containerof
0217 # if LIBBSD_GCC_VERSION >= 0x0301 || !__is_identifier(__typeof__)
0218 #  define __containerof(x, s, m) ({ \
0219     const volatile __typeof__(((s *)0)->m) *__x = (x); \
0220     __DEQUALIFY(s *, (const volatile char *)__x - __offsetof(s, m)); \
0221 })
0222 # else
0223 #  define __containerof(x, s, m) \
0224           __DEQUALIFY(s *, (const volatile char *)(x) - __offsetof(s, m))
0225 # endif
0226 #endif
0227 
0228 #ifndef __RCSID
0229 # define __RCSID(x)
0230 #endif
0231 
0232 #ifndef __FBSDID
0233 # define __FBSDID(x)
0234 #endif
0235 
0236 #ifndef __RCSID
0237 # define __RCSID(x)
0238 #endif
0239 
0240 #ifndef __RCSID_SOURCE
0241 # define __RCSID_SOURCE(x)
0242 #endif
0243 
0244 #ifndef __SCCSID
0245 # define __SCCSID(x)
0246 #endif
0247 
0248 #ifndef __COPYRIGHT
0249 # define __COPYRIGHT(x)
0250 #endif
0251 
0252 #ifndef __DECONST
0253 #define __DECONST(type, var)    ((type)(uintptr_t)(const void *)(var))
0254 #endif
0255 
0256 #ifndef __DEVOLATILE
0257 #define __DEVOLATILE(type, var) ((type)(uintptr_t)(volatile void *)(var))
0258 #endif
0259 
0260 #ifndef __DEQUALIFY
0261 #define __DEQUALIFY(type, var)  ((type)(uintptr_t)(const volatile void *)(var))
0262 #endif
0263 
0264 #endif