Loading...
Searching...
No Matches
Go to the documentation of this file.
21#ifndef LIBDPKG_MACROS_H
22#define LIBDPKG_MACROS_H
30#ifndef LIBDPKG_VOLATILE_API
31#error "The libdpkg API is to be considered volatile, please read 'README.api'."
37#define __has_include(x) 0
42#define __has_warning(w) (0)
45#define DPKG_PRAGMA(x) _Pragma(#x)
48#define DPKG_PRAGMA_CC(x) DPKG_PRAGMA(clang x)
49#elif defined(__GNUC__)
50#define DPKG_PRAGMA_CC(x) DPKG_PRAGMA(GCC x)
52#define DPKG_PRAGMA_CC(x)
55#define DPKG_IGNORE_WARNING(w) \
56 DPKG_PRAGMA_CC(diagnostic push); \
57 DPKG_PRAGMA_CC(diagnostic ignored w)
58#define DPKG_ACCEPT_WARNING() \
59 DPKG_PRAGMA_CC(diagnostic pop)
61#if __has_warning("-Wassign-enum")
62#define DPKG_IGNORE_WARNING_ASSIGN_ENUM() DPKG_IGNORE_WARNING("-Wassign-enum")
63#define DPKG_ACCEPT_WARNING_ASSIGN_ENUM() DPKG_ACCEPT_WARNING()
65#define DPKG_IGNORE_WARNING_ASSIGN_ENUM()
66#define DPKG_ACCEPT_WARNING_ASSIGN_ENUM()
71#ifndef __has_attribute
72#define __has_attribute(x) 0
76#define DPKG_GCC_VERSION (__GNUC__ << 8 | __GNUC_MINOR__)
78#define DPKG_GCC_VERSION 0
81#if DPKG_GCC_VERSION >= 0x0300 || __has_attribute(__unused__)
82#define DPKG_ATTR_UNUSED __attribute__((__unused__))
84#define DPKG_ATTR_UNUSED
87#if DPKG_GCC_VERSION >= 0x0300 || __has_attribute(__const__)
88#define DPKG_ATTR_CONST __attribute__((__const__))
90#define DPKG_ATTR_CONST
93#if DPKG_GCC_VERSION >= 0x0300 || __has_attribute(__pure__)
94#define DPKG_ATTR_PURE __attribute__((__pure__))
99#if DPKG_GCC_VERSION >= 0x0300 || __has_attribute(__malloc__)
100#define DPKG_ATTR_MALLOC __attribute__((__malloc__))
102#define DPKG_ATTR_MALLOC
105#if DPKG_GCC_VERSION >= 0x0300 || __has_attribute(__noreturn__)
106#define DPKG_ATTR_NORET __attribute__((__noreturn__))
108#define DPKG_ATTR_NORET
111#if DPKG_GCC_VERSION >= 0x0300 || __has_attribute(__format__)
112#define DPKG_ATTR_FMT(t, f, a) __attribute__((__format__(t, f, a)))
113#define DPKG_ATTR_PRINTF(n) DPKG_ATTR_FMT(__printf__, n, n + 1)
114#define DPKG_ATTR_VPRINTF(n) DPKG_ATTR_FMT(__printf__, n, 0)
116#define DPKG_ATTR_FMT(t, f, a)
117#define DPKG_ATTR_PRINTF(n)
118#define DPKG_ATTR_VPRINTF(n)
121#if DPKG_GCC_VERSION > 0x0302 || __has_attribute(__nonnull__)
122#define DPKG_ATTR_NONNULL(...) __attribute__((__nonnull__(__VA_ARGS__)))
124#define DPKG_ATTR_NONNULL(...)
127#if DPKG_GCC_VERSION > 0x0302 || __has_attribute(__warn_unused_result__)
128#define DPKG_ATTR_REQRET __attribute__((__warn_unused_result__))
130#define DPKG_ATTR_REQRET
133#if DPKG_GCC_VERSION >= 0x0400 || __has_attribute(__sentinel__)
134#define DPKG_ATTR_SENTINEL __attribute__((__sentinel__))
136#define DPKG_ATTR_SENTINEL
139#if DPKG_GCC_VERSION >= 0x0801 || __has_attribute(__nonstring__)
140#define DPKG_ATTR_NONSTRING __attribute__((__nonstring__))
142#define DPKG_ATTR_NONSTRING
145#if __has_attribute(__enum_extensibility__)
146#define DPKG_ATTR_ENUM_FLAGS \
147 __attribute__((__enum_extensibility__(closed),__flag_enum__))
149#define DPKG_ATTR_ENUM_FLAGS
152#if defined(__cplusplus) && __cplusplus >= 201103L
153#define DPKG_ATTR_THROW(exception)
154#define DPKG_ATTR_NOEXCEPT noexcept
155#elif defined(__cplusplus)
156#define DPKG_ATTR_THROW(exception) throw(exception)
157#define DPKG_ATTR_NOEXCEPT throw()
161#define DPKG_BEGIN_DECLS extern "C" {
162#define DPKG_END_DECLS }
164#define DPKG_BEGIN_DECLS
165#define DPKG_END_DECLS
177#if defined(__cplusplus) || __STDC_VERSION__ > 201710L
178#define DPKG_NULL nullptr
180#define DPKG_NULL NULL
192#if defined(__cplusplus)
193#define DPKG_STATIC_CAST(type, expr) static_cast<type>(expr)
195#define DPKG_STATIC_CAST(type, expr) (type)(expr)
203#define DPKG_BIT(n) (1UL << (n))
211#define array_count(a) (sizeof(a) / sizeof((a)[0]))
217#define min(a, b) ((a) < (b) ? (a) : (b))
221#define max(a, b) ((a) > (b) ? (a) : (b))
237#define clamp(v, l, h) ((v) > (h) ? (h) : ((v) < (l) ? (l) : (v)))