aboutsummaryrefslogtreecommitdiffstats
path: root/Macros.h
diff options
context:
space:
mode:
authorDaniel Lange <DLange@git.local>2024-01-10 11:17:08 +0100
committerDaniel Lange <DLange@git.local>2024-01-10 11:17:08 +0100
commite7372d18a1a661d8c3dba9f51e1f17b5f94171a7 (patch)
treee8270dd60ec096bee8157dbadf029e15ed584592 /Macros.h
parent937052b231259a47d881d539ad5748245ef55b99 (diff)
downloaddebian_htop-e7372d18a1a661d8c3dba9f51e1f17b5f94171a7.tar.gz
debian_htop-e7372d18a1a661d8c3dba9f51e1f17b5f94171a7.tar.bz2
debian_htop-e7372d18a1a661d8c3dba9f51e1f17b5f94171a7.zip
New upstream version 3.3.0
Diffstat (limited to 'Macros.h')
-rw-r--r--Macros.h64
1 files changed, 62 insertions, 2 deletions
diff --git a/Macros.h b/Macros.h
index 5e8891a..051bedb 100644
--- a/Macros.h
+++ b/Macros.h
@@ -1,7 +1,17 @@
#ifndef HEADER_Macros
#define HEADER_Macros
+/*
+htop - Macros.h
+(C) 2020-2023 htop dev team
+Released under the GNU GPLv2+, see the COPYING file
+in the source distribution for its full text.
+*/
#include <assert.h> // IWYU pragma: keep
+#include <math.h>
+#include <stdbool.h>
+#include <string.h> // IWYU pragma: keep
+
#ifndef MINIMUM
#define MINIMUM(a, b) ((a) < (b) ? (a) : (b))
@@ -34,7 +44,6 @@
#ifdef __GNUC__ // defined by GCC and Clang
#define ATTR_FORMAT(type, index, check) __attribute__((format (type, index, check)))
-#define ATTR_NONNULL __attribute__((nonnull))
#define ATTR_NORETURN __attribute__((noreturn))
#define ATTR_UNUSED __attribute__((unused))
#define ATTR_MALLOC __attribute__((malloc))
@@ -42,13 +51,24 @@
#else /* __GNUC__ */
#define ATTR_FORMAT(type, index, check)
-#define ATTR_NONNULL
#define ATTR_NORETURN
#define ATTR_UNUSED
#define ATTR_MALLOC
#endif /* __GNUC__ */
+#ifdef HAVE_ATTR_NONNULL
+
+#define ATTR_NONNULL __attribute__((nonnull))
+#define ATTR_NONNULL_N(...) __attribute__((nonnull(__VA_ARGS__)))
+
+#else
+
+#define ATTR_NONNULL
+#define ATTR_NONNULL_N(...)
+
+#endif /* HAVE_ATTR_NONNULL */
+
#ifdef HAVE_ATTR_ALLOC_SIZE
#define ATTR_ALLOC_SIZE1(a) __attribute__((alloc_size (a)))
@@ -61,6 +81,27 @@
#endif /* HAVE_ATTR_ALLOC_SIZE */
+#ifdef HAVE_ATTR_ACCESS
+
+#define ATTR_ACCESS2(mode, ref) __attribute__((access (mode, ref)))
+#define ATTR_ACCESS3(mode, ref, size) __attribute__((access (mode, ref, size)))
+
+#else
+
+#define ATTR_ACCESS2(mode, ref)
+#define ATTR_ACCESS3(mode, ref, size)
+
+#endif /* HAVE_ATTR_ACCESS */
+
+#define ATTR_ACCESS2_R(ref) ATTR_ACCESS2(read_only, ref)
+#define ATTR_ACCESS3_R(ref, size) ATTR_ACCESS3(read_only, ref, size)
+
+#define ATTR_ACCESS2_RW(ref) ATTR_ACCESS2(read_write, ref)
+#define ATTR_ACCESS3_RW(ref, size) ATTR_ACCESS3(read_write, ref, size)
+
+#define ATTR_ACCESS2_W(ref) ATTR_ACCESS2(write_only, ref)
+#define ATTR_ACCESS3_W(ref, size) ATTR_ACCESS3(write_only, ref, size)
+
// ignore casts discarding const specifier, e.g.
// const char [] -> char * / void *
// const char *[2]' -> char *const *
@@ -77,6 +118,25 @@
#define IGNORE_WCASTQUAL_END
#endif
+/* Cheaper function for checking NaNs. Unlike the standard isnan(), this may
+ throw an FP exception on a "signaling NaN".
+ (ISO/IEC TS 18661-1 and the C23 standard stated that isnan() throws no
+ exceptions even with a "signaling NaN") */
+static inline bool isNaN(double x) {
+ return !isgreaterequal(x, x);
+}
+
+/* Checks if x >= 0.0 but returns false if x is NaN. Because IEEE 754 considers
+ -0.0 == 0.0, this function treats both zeros as nonnegative. */
+static inline bool isNonnegative(double x) {
+ return isgreaterequal(x, 0.0);
+}
+
+/* Checks if x > 0.0 but returns false if x is NaN. */
+static inline bool isPositive(double x) {
+ return isgreater(x, 0.0);
+}
+
/* This subtraction is used by Linux / NetBSD / OpenBSD for calculation of CPU usage items. */
static inline unsigned long long saturatingSub(unsigned long long a, unsigned long long b) {
return a > b ? a - b : 0;

© 2014-2024 Faster IT GmbH | imprint | privacy policy