From 863ebc4bdd91758a2f7d20e846f10f61df2ad409 Mon Sep 17 00:00:00 2001 From: Sebastian Harl Date: Tue, 8 Jul 2014 21:42:45 +0200 Subject: [PATCH] sysdb.h: Added helpers to compare two values. --- src/core/data.c | 10 +++++----- src/include/sysdb.h.in | 5 +++++ 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/core/data.c b/src/core/data.c index 47c54cc..2381636 100644 --- a/src/core/data.c +++ b/src/core/data.c @@ -29,6 +29,8 @@ # include "config.h" #endif /* HAVE_CONFIG_H */ +#include "sysdb.h" + #include "core/data.h" #include "utils/error.h" @@ -109,17 +111,16 @@ sdb_data_cmp(const sdb_data_t *d1, const sdb_data_t *d2) if (d1->type != d2->type) return -1; -#define CMP(a, b) ((a) < (b) ? -1 : (a) > (b) ? 1 : 0) switch (d1->type) { case SDB_TYPE_INTEGER: - return CMP(d1->data.integer, d2->data.integer); + return SDB_CMP(d1->data.integer, d2->data.integer); case SDB_TYPE_DECIMAL: - return CMP(d1->data.decimal, d2->data.decimal); + return SDB_CMP(d1->data.decimal, d2->data.decimal); case SDB_TYPE_STRING: CMP_NULL(d1->data.string, d2->data.string); return strcasecmp(d1->data.string, d2->data.string); case SDB_TYPE_DATETIME: - return CMP(d1->data.datetime, d2->data.datetime); + return SDB_CMP(d1->data.datetime, d2->data.datetime); case SDB_TYPE_BINARY: { int diff; @@ -146,7 +147,6 @@ sdb_data_cmp(const sdb_data_t *d1, const sdb_data_t *d2) default: return -1; } -#undef CMP #undef CMP_NULL } /* sdb_data_cmp */ diff --git a/src/include/sysdb.h.in b/src/include/sysdb.h.in index 6766641..7bd2ad9 100644 --- a/src/include/sysdb.h.in +++ b/src/include/sysdb.h.in @@ -48,6 +48,11 @@ #define SDB_STATIC_ARRAY_LEN(a) (sizeof((a)) / sizeof((a)[0])) +#define SDB_MIN(a, b) ((a) <= (b) ? (a) : (b)) +#define SDB_MAX(a, b) ((a) >= (b) ? (a) : (b)) + +#define SDB_CMP(a, b) ((a) < (b) ? -1 : (a) > (b) ? 1 : 0) + #ifdef __cplusplus extern "C" { #endif -- 2.30.2