Code

sysdb.h: Added helpers to compare two values.
authorSebastian Harl <sh@tokkee.org>
Tue, 8 Jul 2014 19:42:45 +0000 (21:42 +0200)
committerSebastian Harl <sh@tokkee.org>
Tue, 8 Jul 2014 19:42:45 +0000 (21:42 +0200)
src/core/data.c
src/include/sysdb.h.in

index 47c54cc41e5b3e8ed881747c50f28b9a41125410..2381636092ceb03b7d4ef25ae8c9935ec3300583 100644 (file)
@@ -29,6 +29,8 @@
 #      include "config.h"
 #endif /* HAVE_CONFIG_H */
 
 #      include "config.h"
 #endif /* HAVE_CONFIG_H */
 
+#include "sysdb.h"
+
 #include "core/data.h"
 #include "utils/error.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;
 
        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:
        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:
                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:
                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;
                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;
        }
                default:
                        return -1;
        }
-#undef CMP
 #undef CMP_NULL
 } /* sdb_data_cmp */
 
 #undef CMP_NULL
 } /* sdb_data_cmp */
 
index 67666412416d703450d87fc7a52f0231cba0f37a..7bd2ad95c26f6ee19f9dfdc2bdce2acd555483a7 100644 (file)
 
 #define SDB_STATIC_ARRAY_LEN(a) (sizeof((a)) / sizeof((a)[0]))
 
 
 #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
 #ifdef __cplusplus
 extern "C" {
 #endif