]> git.ipfire.org Git - thirdparty/chrony.git/commitdiff
util: add macros for maximum, minimum and clamp
authorMiroslav Lichvar <mlichvar@redhat.com>
Fri, 27 Nov 2015 10:03:16 +0000 (11:03 +0100)
committerMiroslav Lichvar <mlichvar@redhat.com>
Mon, 30 Nov 2015 16:34:53 +0000 (17:34 +0100)
If MAX/MIN are defined in system headers, undefine them first.

ntp_core.c
util.h

index 8987468b5cbe7e8dce2b2cda903928bc955d6e79..26ca39b9003c7d1fdfd81a39fa75619169253d48 100644 (file)
@@ -1404,8 +1404,7 @@ receive_packet(NTP_Packet *message, struct timeval *now, double now_err, NCR_Ins
                            &sample_time,
                            offset, delay, dispersion,
                            root_delay, root_dispersion,
-                           message->stratum > inst->min_stratum ?
-                             message->stratum : inst->min_stratum,
+                           MAX(message->stratum, inst->min_stratum),
                            (NTP_Leap) pkt_leap);
 
       SRC_SelectSource(inst->source);
diff --git a/util.h b/util.h
index 78b7d71af366400b5b511722c3732cd201b3297a..ebd0d208dff00c013e10f29f9c286c86ee400106 100644 (file)
--- a/util.h
+++ b/util.h
@@ -148,4 +148,17 @@ extern int UTI_CheckDirPermissions(const char *path, mode_t perm, uid_t uid, gid
 /* Fill buffer with random bytes */
 extern void UTI_GetRandomBytes(void *buf, unsigned int len);
 
+/* Macros to get maximum and minimum of two values */
+#ifdef MAX
+#undef MAX
+#endif
+#define MAX(x, y) ((x) > (y) ? (x) : (y))
+#ifdef MIN
+#undef MIN
+#endif
+#define MIN(x, y) ((x) < (y) ? (x) : (y))
+
+/* Macro to clamp a value between two values */
+#define CLAMP(min, x, max) (MAX((min), MIN((x), (max))))
+
 #endif /* GOT_UTIL_H */