#pragma once
/***
This file is part of systemd.
Copyright 2010 Lennart Poettering
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
systemd 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <assert.h>
#include <inttypes.h>
#include <stdbool.h>
/* Temporarily disable some warnings */
_Pragma("GCC diagnostic push"); \
_Pragma("GCC diagnostic ignored \"-Wdeclaration-after-statement\"")
#define DISABLE_WARNING_FORMAT_NONLITERAL \
_Pragma("GCC diagnostic push"); \
_Pragma("GCC diagnostic ignored \"-Wformat-nonliteral\"")
#define DISABLE_WARNING_MISSING_PROTOTYPES \
_Pragma("GCC diagnostic push"); \
_Pragma("GCC diagnostic ignored \"-Wmissing-prototypes\"")
#define DISABLE_WARNING_NONNULL \
_Pragma("GCC diagnostic push"); \
_Pragma("GCC diagnostic ignored \"-Wnonnull\"")
#define DISABLE_WARNING_SHADOW \
_Pragma("GCC diagnostic push"); \
_Pragma("GCC diagnostic ignored \"-Wshadow\"")
_Pragma("GCC diagnostic push"); \
_Pragma("GCC diagnostic ignored \"-Wincompatible-pointer-types\"")
#define REENABLE_WARNING \
_Pragma("GCC diagnostic pop")
/* automake test harness */
#define XSTRINGIFY(x) #x
#define XCONCATENATE(x, y) x ## y
/* Rounds up */
#if __SIZEOF_POINTER__ == 8
#else
#error "Wut? Pointers are neither 4 nor 8 bytes long?"
#endif
}
/* align to next higher power-of-2 (except for: 0 => 0, overflow => 0) */
static inline unsigned long ALIGN_POWER2(unsigned long u) {
/* clz(0) is undefined */
if (u == 1)
return 1;
/* left-shift overflow is undefined */
return 0;
}
#define ELEMENTSOF(x) \
sizeof(x)/sizeof((x)[0]), \
(void)0))
/*
* container_of - cast a member of a structure out to the containing structure
* @ptr: the pointer to the member.
* @type: the type of the container struct this is embedded in.
* @member: the name of the member within the struct.
*/
__extension__ ({ \
})
__extension__ ({ \
})
/* evaluates to (void) if _A or _B are not constant or of different types */
__builtin_constant_p(_A) && \
__builtin_constant_p(_B) && \
(void)0))
/* takes two types and returns the size of the larger one */
#define MAX3(x,y,z) \
__extension__ ({ \
})
__extension__ ({ \
})
#define MIN3(x,y,z) \
__extension__ ({ \
})
__extension__ ({ \
})
__extension__ ({ \
})
/* [(x + y - 1) / y] suffers from an integer overflow, even though the
* computation should be possible in the given type. Therefore, we use
* [x / y + !!(x % y)]. Note that on "Real CPUs" a division returns both the
* quotient and the remainder, so both should be equally fast. */
__extension__ ({ \
})
do { \
if (_unlikely_(!(expr))) \
} while (false)
/* We override the glibc assert() here. */
#ifdef NDEBUG
#else
#endif
#define assert_not_reached(t) \
do { \
} while (false)
#if defined(static_assert)
/* static_assert() is sometimes defined in a way that trips up
* -Wdeclaration-after-statement, hence let's temporarily turn off
* this warning around it. */
#else
char x[(expr) ? 0 : -1]; \
}; \
#endif
? (true) \
do { \
return (r); \
} while (false)
do { \
return (r); \
} \
} while (false)
/* Returns the number of chars needed to format variables of the
* specified type as a decimal string. Adds in extra space for a
* negative '-' prefix (hence works correctly on signed
* types). Includes space for the trailing NUL. */
#define DECIMAL_STR_WIDTH(x) \
({ \
unsigned ans = 1; \
while (_x_ /= 10) \
ans++; \
ans; \
})
#define CASE_F(X) case X:
#define GET_CASE_F(_1,_2,_3,_4,_5,_6,_7,_8,_9,_10,_11,_12,_13,_14,_15,_16,_17,_18,_19,_20,NAME,...) NAME
#define FOR_EACH_MAKE_CASE(...) \
GET_CASE_F(__VA_ARGS__,CASE_F_20,CASE_F_19,CASE_F_18,CASE_F_17,CASE_F_16,CASE_F_15,CASE_F_14,CASE_F_13,CASE_F_12,CASE_F_11, \
#define IN_SET(x, ...) \
({ \
bool _found = false; \
/* If the build breaks in the line below, you need to extend the case macros */ \
static _unused_ char _static_assert__macros_need_to_be_extended[20 - sizeof((int[]){__VA_ARGS__})/sizeof(int)]; \
switch(x) { \
_found = true; \
break; \
default: \
break; \
} \
_found; \
})
/* Define C11 thread_local attribute even on older gcc compiler
* version */
#ifndef thread_local
/*
* Don't break on glibc < 2.16 that doesn't define __STDC_NO_THREADS__
*/
#if __STDC_VERSION__ >= 201112L && !(defined(__STDC_NO_THREADS__) || (defined(__GNU_LIBRARY__) && __GLIBC__ == 2 && __GLIBC_MINOR__ < 16))
#else
#endif
#endif
/* Define C11 noreturn without <stdnoreturn.h> and even on older gcc
* compiler versions */
#ifndef noreturn
#if __STDC_VERSION__ >= 201112L
#else
#endif
#endif
if (*p) \
func(*p); \
} \
#include "log.h"