a wrapper around qsort() that ensures the comparison function is
type safe.
*/
+#ifndef TYPESAFE_QSORT
#define TYPESAFE_QSORT(base, numel, comparison) \
do { \
if (numel > 1) { \
- qsort(base, numel, sizeof((base)[0]), QSORT_CAST comparison); \
+ qsort(base, numel, sizeof((base)[0]), (int (*)(const void *, const void *))comparison); \
assert(comparison(&((base)[0]), &((base)[1])) <= 0); \
} \
} while (0)
+#endif
#endif
* the resulting DNs consistent, plus to ensure that we put
* 'DELETED' first, so it can be very quickly recognised
*/
- qsort(dn->ext_components, dn->ext_comp_num, sizeof(dn->ext_components[0]),
- ldb_dn_extended_component_compare);
+ TYPESAFE_QSORT(dn->ext_components, dn->ext_comp_num,
+ ldb_dn_extended_component_compare);
for (i = 0; i < dn->ext_comp_num; i++) {
const struct ldb_dn_extended_syntax *ext_syntax;
*/
void ldb_msg_sort_elements(struct ldb_message *msg)
{
- qsort(msg->elements, msg->num_elements, sizeof(struct ldb_message_element),
- (comparison_fn_t)ldb_msg_element_compare_name);
+ TYPESAFE_QSORT(msg->elements, msg->num_elements,
+ ldb_msg_element_compare_name);
}
/*
} \
} while (0)
+/* allow ldb to also call TYPESAFE_QSORT() */
+#ifndef TYPESAFE_QSORT
+#define TYPESAFE_QSORT(base, numel, comparison) \
+do { \
+ if (numel > 1) { \
+ qsort(base, numel, sizeof((base)[0]), (int (*)(const void *, const void *))comparison); \
+ comparison(&((base)[0]), &((base)[1])); \
+ } \
+} while (0)
+#endif
+
/**
return;
}
- qsort(list->dn, list->count, sizeof(struct ldb_val), (comparison_fn_t) dn_list_cmp);
+ TYPESAFE_QSORT(list->dn, list->count, dn_list_cmp);
new_count = 1;
for (i=1; i<list->count; i++) {
#include "ldb.h"
#include "tools/cmdline.h"
#include "ldbutil.h"
+#include "replace.h"
-static int dn_cmp(const void *p1, const void *p2)
+static int dn_cmp(struct ldb_message **msg1, struct ldb_message **msg2)
{
- const struct ldb_message *msg1, *msg2;
- msg1 = *(const struct ldb_message * const *)p1;
- msg2 = *(const struct ldb_message * const *)p2;
- return ldb_dn_compare(msg1->dn, msg2->dn);
+ return ldb_dn_compare((*msg1)->dn, (*msg2)->dn);
}
static int ldb_delete_recursive(struct ldb_context *ldb, struct ldb_dn *dn,struct ldb_control **req_ctrls)
if (ret != LDB_SUCCESS) return -1;
/* sort the DNs, deepest first */
- qsort(res->msgs, res->count, sizeof(res->msgs[0]), dn_cmp);
+ TYPESAFE_QSORT(res->msgs, res->count, dn_cmp);
for (i = 0; i < res->count; i++) {
if (ldb_delete_ctrl(ldb, res->msgs[i]->dn,req_ctrls) == 0) {