summaryrefslogtreecommitdiff
path: root/source4/lib/ldb/include
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2010-02-13 13:26:16 +1100
committerAndrew Tridgell <tridge@samba.org>2010-02-13 22:36:12 +1100
commit46dfa9dfbdd7649cd8a71e9727aff830a58e4d55 (patch)
treefe3ff6b6d078730d3dbe13e0e4188fd0ded9d605 /source4/lib/ldb/include
parent1da87fc988d0660f9c868ec9350664a3f7f51942 (diff)
downloadsamba-46dfa9dfbdd7649cd8a71e9727aff830a58e4d55.tar.gz
samba-46dfa9dfbdd7649cd8a71e9727aff830a58e4d55.tar.bz2
samba-46dfa9dfbdd7649cd8a71e9727aff830a58e4d55.zip
s4-ldb: added LDB_TYPESAFE_QSORT()
Like TYPESAFE_QSORT() but for the ldb_qsort() function
Diffstat (limited to 'source4/lib/ldb/include')
-rw-r--r--source4/lib/ldb/include/ldb.h18
1 files changed, 18 insertions, 0 deletions
diff --git a/source4/lib/ldb/include/ldb.h b/source4/lib/ldb/include/ldb.h
index 1958fd740b..26a196f311 100644
--- a/source4/lib/ldb/include/ldb.h
+++ b/source4/lib/ldb/include/ldb.h
@@ -1985,6 +1985,24 @@ time_t ldb_string_utc_to_time(const char *s);
void ldb_qsort (void *const pbase, size_t total_elems, size_t size, void *opaque, ldb_qsort_cmp_fn_t cmp);
+#ifndef discard_const
+#define discard_const(ptr) ((void *)((uintptr_t)(ptr)))
+#endif
+
+/*
+ a wrapper around ldb_qsort() that ensures the comparison function is
+ type safe. This will produce a compilation warning if the types
+ don't match
+ */
+#define LDB_TYPESAFE_QSORT(base, numel, opaque, comparison) \
+do { \
+ if (numel > 1) { \
+ ldb_qsort(base, numel, sizeof((base)[0]), discard_const(opaque), (ldb_qsort_cmp_fn_t)comparison); \
+ comparison(&((base)[0]), &((base)[1]), opaque); \
+ } \
+} while (0)
+
+
/**
Convert an array of string represention of a control into an array of ldb_control structures