diff options
author | Jan Janssen <medhefgo@web.de> | 2021-08-11 14:59:46 +0200 |
---|---|---|
committer | Jan Janssen <medhefgo@web.de> | 2021-08-11 14:59:46 +0200 |
commit | f862e847246b5588d9d6ed7d91da11b6adbf39e7 (patch) | |
tree | 91bc9418e754ac7aea79c432b9f29273de3c7824 /src/fundamental | |
parent | d178203d8e2dae9bba48790a93031f2e776a2f83 (diff) | |
download | systemd-f862e847246b5588d9d6ed7d91da11b6adbf39e7.tar.gz |
macro: Move some macros to macro-fundamental.h
Also, make sure STRLEN works with wide strings too.
Diffstat (limited to 'src/fundamental')
-rw-r--r-- | src/fundamental/macro-fundamental.h | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/fundamental/macro-fundamental.h b/src/fundamental/macro-fundamental.h index e9fb4d3938..91b24a1826 100644 --- a/src/fundamental/macro-fundamental.h +++ b/src/fundamental/macro-fundamental.h @@ -14,6 +14,22 @@ #define _used_ __attribute__((__used__)) #define _unused_ __attribute__((__unused__)) #define _cleanup_(x) __attribute__((__cleanup__(x))) +#define _likely_(x) (__builtin_expect(!!(x), 1)) +#define _unlikely_(x) (__builtin_expect(!!(x), 0)) +#if __GNUC__ >= 7 +#define _fallthrough_ __attribute__((__fallthrough__)) +#else +#define _fallthrough_ +#endif +/* Define C11 noreturn without <stdnoreturn.h> and even on older gcc + * compiler versions */ +#ifndef _noreturn_ +#if __STDC_VERSION__ >= 201112L +#define _noreturn_ _Noreturn +#else +#define _noreturn_ __attribute__((__noreturn__)) +#endif +#endif #define XSTRINGIFY(x) #x #define STRINGIFY(x) XSTRINGIFY(x) @@ -233,3 +249,10 @@ (ptr) = NULL; \ _ptr_; \ }) + +/* + * STRLEN - return the length of a string literal, minus the trailing NUL byte. + * Contrary to strlen(), this is a constant expression. + * @x: a string literal. + */ +#define STRLEN(x) (sizeof(""x"") - sizeof(typeof(x[0]))) |