util: add macros for maximum, minimum and clamp

If MAX/MIN are defined in system headers, undefine them first.
This commit is contained in:
Miroslav Lichvar 2015-11-27 11:03:16 +01:00
parent 8b235297a5
commit 801830df57
2 changed files with 14 additions and 2 deletions

View 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);

13
util.h
View file

@ -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 */