lite.h: Add min() and max() macros

These macros take care to avoid double evaluation.

Signed-off-by: Tobias Waldekranz <tobias@waldekranz.com>
Signed-off-by: Joachim Nilsson <troglobit@gmail.com>
This commit is contained in:
Tobias Waldekranz authored and Joachim Nilsson committed 2016-01-05 13:16:34 +01:00
1 parent e42aca8856
commit 61254279b9
1 file changed
+14
+14
View File
@@ -181,6 +181,20 @@ static inline int string_case_compare (const char *a, const char *b)
return strlen (a) == strlen (b) && !strcasecmp (a, b);
}
#define min(a,b) \
({ \
__typeof__ (a) _a = (a); \
__typeof__ (b) _b = (b); \
_a < _b ? _a : _b; \
})
#define max(a,b) \
({ \
__typeof__ (a) _a = (a); \
__typeof__ (b) _b = (b); \
_a > _b ? _a : _b; \
})
/* Compat */
#define copy_filep(src,dst) fcopyfile(src,dst)
#define pidfile_read_pid(file) pifile_read(file)