array_append(&ctx->strings, &value, 1);
}
-static int config_string_cmp(const void *p1, const void *p2)
+static int config_string_cmp(const char *const *p1, const char *const *p2)
{
- const char *s1 = *(const char *const *)p1;
- const char *s2 = *(const char *const *)p2;
+ const char *s1 = *p1, *s2 = *p2;
unsigned int i = 0;
while (s1[i] == s2[i]) {
ARRAY_TYPE(const_string) prefixes_arr;
ARRAY_TYPE(uint) prefix_idx_stack;
struct config_request_get_string_ctx ctx;
- const char **strings, *const *args, *p, *str, *const *prefixes;
+ const char *const *strings, *const *args, *p, *str, *const *prefixes;
const char *key, *value;
unsigned int i, j, count, len, prefix_count, skip_len;
unsigned int indent = 0, prefix_idx = -1U;
config_request_handle(filter, module, flags,
config_request_get_strings, &ctx);
- strings = array_get_modifiable(&ctx.strings, &count);
- qsort(strings, count, sizeof(*strings), config_string_cmp);
+ array_sort(&ctx.strings, config_string_cmp);
+ strings = array_get(&ctx.strings, &count);
p_array_init(&prefixes_arr, ctx.pool, 32);
for (i = 0; i < count && strings[i][0] == '-'; i++) T_BEGIN {
}
}
-static int command_cmp(const void *p1, const void *p2)
+static int command_cmp(const struct command *c1, const struct command *c2)
{
- const struct command *c1 = p1, *c2 = p2;
-
return strcasecmp(c1->name, c2->name);
}
struct command *command_find(const char *name)
{
- void *base;
+ const void *base;
unsigned int count;
- base = array_get_modifiable(&imap_commands, &count);
if (commands_unsorted) {
- qsort(base, count, sizeof(struct command), command_cmp);
+ array_sort(&imap_commands, command_cmp);
commands_unsorted = FALSE;
}
+ base = array_get(&imap_commands, &count);
return bsearch(name, base, count, sizeof(struct command),
command_bsearch);
}
static ARRAY_DEFINE(fetch_handlers, struct imap_fetch_handler);
-static int imap_fetch_handler_cmp(const void *p1, const void *p2)
+static int imap_fetch_handler_cmp(const struct imap_fetch_handler *h1,
+ const struct imap_fetch_handler *h2)
{
- const struct imap_fetch_handler *h1 = p1, *h2 = p2;
-
return strcmp(h1->name, h2->name);
}
void imap_fetch_handlers_register(const struct imap_fetch_handler *handlers,
size_t count)
{
- struct imap_fetch_handler *all_handlers;
- unsigned int all_count;
-
array_append(&fetch_handlers, handlers, count);
-
- all_handlers = array_get_modifiable(&fetch_handlers, &all_count);
- qsort(all_handlers, all_count, sizeof(*all_handlers),
- imap_fetch_handler_cmp);
+ array_sort(&fetch_handlers, imap_fetch_handler_cmp);
}
static int imap_fetch_handler_bsearch(const void *name_p, const void *handler_p)
}
}
-static int header_lookup_line_cmp(const void *p1, const void *p2)
+static int header_lookup_line_cmp(const struct header_lookup_line *l1,
+ const struct header_lookup_line *l2)
{
- const struct header_lookup_line *l1 = p1, *l2 = p2;
-
return (int)l1->line_num - (int)l2->line_num;
}
/* we need to return headers in the order they existed originally.
we can do this by sorting the messages by their line numbers. */
+ array_sort(&ctx.lines, header_lookup_line_cmp);
lines = array_get_modifiable(&ctx.lines, &count);
- qsort(lines, count, sizeof(*lines), header_lookup_line_cmp);
/* then start filling dest buffer from the headers */
for (i = 0; i < count; i++) {
bool extended;
};
-static int rfc2231_parameter_cmp(const void *p1, const void *p2)
+static int rfc2231_parameter_cmp(const struct rfc2231_parameter *r1,
+ const struct rfc2231_parameter *r2)
{
- const struct rfc2231_parameter *r1 = p1, *r2 = p2;
int ret;
ret = strcmp(r1->key, r2->key);
{
ARRAY_TYPE(const_string) result;
ARRAY_DEFINE(rfc2231_params_arr, struct rfc2231_parameter);
- struct rfc2231_parameter rfc2231_param, *rfc2231_params;
+ struct rfc2231_parameter rfc2231_param;
+ const struct rfc2231_parameter *rfc2231_params;
const char *key, *value, *p, *p2;
string_t *str;
unsigned int i, j, count, next, next_idx;
/* Merge the RFC 2231 parameters. Since their order isn't guaranteed to
be ascending, start by sorting them. */
- rfc2231_params = array_get_modifiable(&rfc2231_params_arr, &count);
- qsort(rfc2231_params, count, sizeof(*rfc2231_params),
- rfc2231_parameter_cmp);
+ array_sort(&rfc2231_params_arr, rfc2231_parameter_cmp);
+ rfc2231_params = array_get(&rfc2231_params_arr, &count);
/* keys are now sorted primarily by their name and secondarily by
their index. If any indexes are missing, fallback to assuming
return ret;
}
-static int environ_cmp(const void *p1, const void *p2)
+static int environ_cmp(char *const *s1, char *const *s2)
{
- const char *const *s1 = p1, *const *s2 = p2;
-
return -strcmp(*s1, *s2);
}
extern char **environ;
ARRAY_TYPE(string) sorted_envs_arr;
const char *key, *value;
- char **sorted_envs;
+ char *const *sorted_envs;
unsigned int i, count;
int ret = 0;
i_array_init(&sorted_envs_arr, 128);
for (i = 0; environ[i] != NULL; i++)
array_append(&sorted_envs_arr, &environ[i], 1);
- sorted_envs = array_get_modifiable(&sorted_envs_arr, &count);
- qsort(sorted_envs, count, sizeof(*sorted_envs), environ_cmp);
+ array_sort(&sorted_envs_arr, environ_cmp);
+ sorted_envs = array_get(&sorted_envs_arr, &count);
for (i = 0; i < count && ret == 0; i++) {
value = strchr(sorted_envs[i], '=');
{
struct dbox_map *map = ctx->storage->map;
const struct mail_index_header *hdr;
- struct dbox_rebuild_msg **msgs, **pos;
+ struct dbox_rebuild_msg *const *msgs, **pos;
struct dbox_rebuild_msg search_msg, *search_msgp = &search_msg;
struct dbox_mail_lookup_rec rec;
uint32_t seq;
unsigned int count;
- msgs = array_get_modifiable(&ctx->msgs, &count);
if (ctx->msgs_unsorted)
- qsort(msgs, count, sizeof(*msgs), dbox_rebuild_msg_offset_cmp);
+ array_sort(&ctx->msgs, dbox_rebuild_msg_offset_cmp);
+ msgs = array_get_modifiable(&ctx->msgs, &count);
hdr = mail_index_get_header(ctx->sync_view);
for (seq = 1; seq <= hdr->messages_count; seq++) {
if (dbox_map_view_lookup_rec(map, ctx->sync_view,
/* afterwards we're interested in looking up map_uids.
re-sort the messages to make it easier. */
- qsort(msgs, count, sizeof(*msgs), dbox_rebuild_msg_uid_cmp);
+ array_sort(&ctx->msgs, dbox_rebuild_msg_uid_cmp);
return 0;
}
struct ostream *output = NULL;
struct dbox_map_append_context *append_ctx;
ARRAY_TYPE(dbox_map_file_msg) msgs_arr;
- struct dbox_map_file_msg *msgs;
+ const struct dbox_map_file_msg *msgs;
ARRAY_TYPE(seq_range) expunged_map_uids;
ARRAY_TYPE(uint32_t) copied_map_uids;
unsigned int i, count;
dbox_file_unlock(file);
return -1;
}
- msgs = array_get_modifiable(&msgs_arr, &count);
/* sort messages by their offset */
- qsort(msgs, count, sizeof(*msgs), dbox_map_file_msg_offset_cmp);
+ array_sort(&msgs_arr, dbox_map_file_msg_offset_cmp);
+ msgs = array_get(&msgs_arr, &count);
append_ctx = dbox_map_append_begin_storage(file->storage);
i_array_init(&copied_map_uids, I_MIN(count, 1));
i_array_init(&expunged_map_uids, I_MIN(count, 1));
static const enum message_parser_flags msg_parser_flags =
MESSAGE_PARSER_FLAG_SKIP_BODY_BLOCK;
-static int header_line_cmp(const void *p1, const void *p2)
+static int header_line_cmp(const struct index_mail_line *l1,
+ const struct index_mail_line *l2)
{
- const struct index_mail_line *l1 = p1, *l2 = p2;
int diff;
diff = (int)l1->field_idx - (int)l2->field_idx;
static void index_mail_parse_header_finish(struct index_mail *mail)
{
- struct index_mail_line *lines;
+ const struct index_mail_line *lines;
const unsigned char *header, *data;
const uint8_t *match;
buffer_t *buf;
unsigned int i, j, count, match_idx, match_count;
bool noncontiguous;
- lines = array_get_modifiable(&mail->header_lines, &count);
-
/* sort it first so fields are grouped together and ordered by
line number */
- qsort(lines, count, sizeof(*lines), header_line_cmp);
+ array_sort(&mail->header_lines, header_line_cmp);
+ lines = array_get(&mail->header_lines, &count);
match = array_get(&mail->header_match, &match_count);
header = buffer_get_data(mail->header_data, NULL);
buf = buffer_create_dynamic(pool_datastack_create(), 256);
return 0;
}
-static void index_sort_nodes_by_seq(struct sort_string_context *ctx)
-{
- struct mail_sort_node *nodes;
- unsigned int count;
-
- nodes = array_get_modifiable(&ctx->zero_nodes, &count);
- qsort(nodes, count, sizeof(struct mail_sort_node), sort_node_seq_cmp);
-
- nodes = array_get_modifiable(&ctx->nonzero_nodes, &count);
- qsort(nodes, count, sizeof(struct mail_sort_node), sort_node_seq_cmp);
-}
-
static void index_sort_generate_seqs(struct sort_string_context *ctx)
{
struct mail_sort_node *nodes, *nodes2;
index_sort_node_add(ctx, &node);
}
-static int sort_node_zero_string_cmp(const void *p1, const void *p2)
+static int sort_node_zero_string_cmp(const struct mail_sort_node *n1,
+ const struct mail_sort_node *n2)
{
struct sort_string_context *ctx = static_zero_cmp_context;
- const struct mail_sort_node *n1 = p1, *n2 = p2;
int ret;
ret = strcmp(ctx->sort_strings[n1->seq], ctx->sort_strings[n2->seq]);
/* we have all strings, sort nodes based on them */
static_zero_cmp_context = ctx;
- qsort(nodes, count, sizeof(struct mail_sort_node),
- sort_node_zero_string_cmp);
+ array_sort(&ctx->zero_nodes, sort_node_zero_string_cmp);
}
static const char *
}
}
-static int sort_node_cmp(const void *p1, const void *p2)
+static int sort_node_cmp(const struct mail_sort_node *n1,
+ const struct mail_sort_node *n2)
{
struct sort_string_context *ctx = static_zero_cmp_context;
- const struct mail_sort_node *n1 = p1, *n2 = p2;
if (n1->sort_id < n2->sort_id)
return !ctx->reverse ? -1 : 1;
void index_sort_list_finish_string(struct mail_search_sort_program *program)
{
struct sort_string_context *ctx = program->context;
- struct mail_sort_node *nodes;
+ const struct mail_sort_node *nodes;
unsigned int i, count;
uint32_t seq;
- nodes = array_get_modifiable(&ctx->nonzero_nodes, &count);
-
static_zero_cmp_context = ctx;
if (array_count(&ctx->zero_nodes) == 0) {
/* fast path: we have all sort IDs */
- qsort(nodes, count, sizeof(struct mail_sort_node),
- sort_node_cmp);
+ array_sort(&ctx->nonzero_nodes, sort_node_cmp);
if (!array_is_created(&program->seqs))
i_array_init(&program->seqs, count);
else
array_clear(&program->seqs);
+
+ nodes = array_get(&ctx->nonzero_nodes, &count);
for (i = 0; i < count; i++) {
seq = nodes[i].seq;
array_append(&program->seqs, &seq, 1);
} else {
if (ctx->seqs_nonsorted) {
/* the nodes need to be sorted by sequence initially */
- index_sort_nodes_by_seq(ctx);
+ array_sort(&ctx->zero_nodes, sort_node_seq_cmp);
+ array_sort(&ctx->nonzero_nodes, sort_node_seq_cmp);
}
/* we have to add some sort IDs. we'll do this for all
/* add messages not in seqs list */
index_sort_add_missing(ctx);
/* sort all messages with sort IDs */
- nodes = array_get_modifiable(&ctx->nonzero_nodes, &count);
- qsort(nodes, count, sizeof(struct mail_sort_node),
- sort_node_cmp);
+ array_sort(&ctx->nonzero_nodes, sort_node_cmp);
for (;;) {
/* sort all messages without sort IDs */
index_sort_zeroes(ctx);
array_reverse(&ctx->sorted_nodes);
}
- nodes = array_get_modifiable(&ctx->sorted_nodes, &count);
+ nodes = array_get(&ctx->sorted_nodes, &count);
array_clear(&program->seqs);
for (i = 0; i < count; i++) {
if (nodes[i].wanted) {
program->sort_list_add(program, mail);
}
-static int sort_node_date_cmp(const void *p1, const void *p2)
+static int sort_node_date_cmp(const struct mail_sort_node_date *n1,
+ const struct mail_sort_node_date *n2)
{
struct sort_cmp_context *ctx = &static_node_cmp_context;
- const struct mail_sort_node_date *n1 = p1, *n2 = p2;
if (n1->date < n2->date)
return !ctx->reverse ? -1 : 1;
index_sort_list_finish_date(struct mail_search_sort_program *program)
{
ARRAY_TYPE(mail_sort_node_date) *nodes = program->context;
- struct mail_sort_node_date *date_nodes;
- unsigned int count;
- date_nodes = array_get_modifiable(nodes, &count);
- qsort(date_nodes, count, sizeof(struct mail_sort_node_date),
- sort_node_date_cmp);
+ array_sort(nodes, sort_node_date_cmp);
memcpy(&program->seqs, nodes, sizeof(program->seqs));
i_free(nodes);
program->context = NULL;
}
-static int sort_node_size_cmp(const void *p1, const void *p2)
+static int sort_node_size_cmp(const struct mail_sort_node_size *n1,
+ const struct mail_sort_node_size *n2)
{
struct sort_cmp_context *ctx = &static_node_cmp_context;
- const struct mail_sort_node_size *n1 = p1, *n2 = p2;
if (n1->size < n2->size)
return !ctx->reverse ? -1 : 1;
index_sort_list_finish_size(struct mail_search_sort_program *program)
{
ARRAY_TYPE(mail_sort_node_size) *nodes = program->context;
- struct mail_sort_node_size *size_nodes;
- unsigned int count;
- size_nodes = array_get_modifiable(nodes, &count);
- qsort(size_nodes, count, sizeof(struct mail_sort_node_size),
- sort_node_size_cmp);
+ array_sort(nodes, sort_node_size_cmp);
memcpy(&program->seqs, nodes, sizeof(program->seqs));
i_free(nodes);
program->context = NULL;
}
-static int sort_node_float_cmp(const void *p1, const void *p2)
+static int sort_node_float_cmp(const struct mail_sort_node_float *n1,
+ const struct mail_sort_node_float *n2)
{
struct sort_cmp_context *ctx = &static_node_cmp_context;
- const struct mail_sort_node_float *n1 = p1, *n2 = p2;
if (n1->num < n2->num)
return !ctx->reverse ? -1 : 1;
index_sort_list_finish_float(struct mail_search_sort_program *program)
{
ARRAY_TYPE(mail_sort_node_float) *nodes = program->context;
- struct mail_sort_node_float *float_nodes;
- unsigned int count;
- float_nodes = array_get_modifiable(nodes, &count);
- qsort(float_nodes, count, sizeof(struct mail_sort_node_float),
- sort_node_float_cmp);
+ array_sort(nodes, sort_node_float_cmp);
memcpy(&program->seqs, nodes, sizeof(program->seqs));
i_free(nodes);
program->context = NULL;
node->reply_or_forward = is_reply_or_forward;
}
-static int mail_thread_child_node_cmp(const void *p1, const void *p2)
+static int mail_thread_child_node_cmp(const struct mail_thread_child_node *c1,
+ const struct mail_thread_child_node *c2)
{
- const struct mail_thread_child_node *c1 = p1, *c2 = p2;
-
if (c1->sort_date < c2->sort_date)
return -1;
if (c1->sort_date > c2->sort_date)
return 0;
}
+static int mail_thread_root_node_cmp(const struct mail_thread_root_node *r1,
+ const struct mail_thread_root_node *r2)
+{
+ return mail_thread_child_node_cmp(&r1->node, &r2->node);
+}
+
static uint32_t
thread_lookup_existing(struct thread_finish_context *ctx, uint32_t idx)
{
ARRAY_TYPE(mail_thread_child_node) *sorted_children)
{
const struct mail_thread_shadow_node *shadows;
- struct mail_thread_child_node child, *children;
+ struct mail_thread_child_node child;
unsigned int count;
memset(&child, 0, sizeof(child));
}
/* sort the children */
- children = array_get_modifiable(sorted_children, &count);
- qsort(children, count, sizeof(*children), mail_thread_child_node_cmp);
+ array_sort(sorted_children, mail_thread_child_node_cmp);
}
static void gather_base_subjects(struct thread_finish_context *ctx)
}
}
array_free(&sorted_children);
- qsort(roots, count, sizeof(*roots), mail_thread_child_node_cmp);
+ array_sort(&ctx->roots, mail_thread_root_node_cmp);
}
static int mail_thread_root_node_idx_cmp(const void *key, const void *value)
if (root->node.sort_date < child.sort_date)
root->node.sort_date = child.sort_date;
}
- qsort(roots, root_count, sizeof(*roots), mail_thread_child_node_cmp);
+ array_sort(&ctx->roots, mail_thread_root_node_cmp);
}
static void mail_thread_create_shadows(struct thread_finish_context *ctx,
{
struct maildir_mailbox *mbox = ctx->mbox;
struct mail_keywords *kw;
- unsigned int i, j, old_count, new_count, *old_indexes, *new_indexes;
+ unsigned int i, j, old_count, new_count;
+ const unsigned int *old_indexes, *new_indexes;
bool have_indexonly_keywords;
int diff;
}
/* sort the keywords */
- old_indexes = array_get_modifiable(&ctx->idx_keywords, &old_count);
- qsort(old_indexes, old_count, sizeof(*old_indexes), uint_cmp);
- new_indexes = array_get_modifiable(&ctx->keywords, &new_count);
- qsort(new_indexes, new_count, sizeof(*new_indexes), uint_cmp);
+ array_sort(&ctx->idx_keywords, uint_cmp);
+ array_sort(&ctx->keywords, uint_cmp);
/* drop keywords that are in index-only. we don't want to touch them. */
+ old_indexes = array_get(&ctx->idx_keywords, &old_count);
have_indexonly_keywords = FALSE;
for (i = old_count; i > 0; i--) {
if (old_indexes[i-1] < MAILDIR_MAX_KEYWORDS)
so first remove the unwanted keywords and then add back the wanted
ones. we can get these lists easily by removing common elements
from old and new keywords. */
- new_indexes = array_get_modifiable(&ctx->keywords, &new_count);
+ new_indexes = array_get(&ctx->keywords, &new_count);
for (i = j = 0; i < old_count && j < new_count; ) {
diff = (int)old_indexes[i] - (int)new_indexes[j];
if (diff == 0) {
array_delete(&ctx->keywords, j, 1);
array_delete(&ctx->idx_keywords, i, 1);
- old_indexes = array_get_modifiable(&ctx->idx_keywords,
- &old_count);
- new_indexes = array_get_modifiable(&ctx->keywords,
- &new_count);
+ old_indexes = array_get(&ctx->idx_keywords, &old_count);
+ new_indexes = array_get(&ctx->keywords, &new_count);
} else if (diff < 0) {
i++;
} else {
static void maildir_uidlist_records_sort_by_uid(struct maildir_uidlist *uidlist)
{
- struct maildir_uidlist_rec **recs;
- unsigned int count;
-
- recs = array_get_modifiable(&uidlist->records, &count);
- qsort(recs, count, sizeof(*recs), maildir_uid_cmp);
-
+ array_sort(&uidlist->records, maildir_uid_cmp);
uidlist->unsorted = FALSE;
}
static void maildir_uidlist_swap(struct maildir_uidlist_sync_ctx *ctx)
{
struct maildir_uidlist *uidlist = ctx->uidlist;
- struct maildir_uidlist_rec **recs;
- unsigned int count;
/* buffer is unsorted, sort it by UID */
- recs = array_get_modifiable(&ctx->records, &count);
- qsort(recs, count, sizeof(*recs), maildir_uid_cmp);
+ array_sort(&ctx->records, maildir_uid_cmp);
array_free(&uidlist->records);
uidlist->records = ctx->records;
ctx->record_pool = NULL;
if (ctx->new_files_count != 0) {
- ctx->first_nouid_pos = count - ctx->new_files_count;
+ ctx->first_nouid_pos = array_count(&uidlist->records) -
+ ctx->new_files_count;
maildir_uidlist_assign_uids(ctx);
} else {
ctx->uidlist->change_counter++;
return module;
}
-static int module_name_cmp(const void *p1, const void *p2)
+static int module_name_cmp(const char *const *n1, const char *const *n2)
{
- const char *const *n1 = p1, *const *n2 = p2;
const char *s1 = *n1, *s2 = *n2;
if (strncmp(s1, "lib", 3) == 0)
{
DIR *dirp;
struct dirent *d;
- const char *name, *p, **names_p;
+ const char *name, *p, *const *names_p;
const char **module_names_arr;
struct module *modules, *module, **module_pos;
unsigned int i, count;
array_append(&names, &name, 1);
}
- names_p = array_get_modifiable(&names, &count);
- qsort(names_p, count, sizeof(const char *), module_name_cmp);
+ array_sort(&names, module_name_cmp);
+ names_p = array_get(&names, &count);
if (module_names == NULL)
module_names_arr = NULL;
acl_rights_alloc(pool_t pool, ARRAY_TYPE(const_string) *rights_arr,
bool dup_strings)
{
- const char **ret, **rights;
+ const char **ret, *const *rights;
unsigned int i, dest, count;
/* sort the rights first so we can easily drop duplicates */
- rights = array_get_modifiable(rights_arr, &count);
- qsort(rights, count, sizeof(*rights), i_strcmp_p);
+ array_sort(rights_arr, i_strcmp_p);
/* @UNSAFE */
+ rights = array_get(rights_arr, &count);
ret = p_new(pool, const char *, count + 1);
if (count > 0) {
ret[0] = rights[0];
return 0;
}
-static int acl_rights_cmp(const void *p1, const void *p2)
+static int acl_rights_cmp(const struct acl_rights *r1,
+ const struct acl_rights *r2)
{
- const struct acl_rights *r1 = p1, *r2 = p2;
int ret;
if (r1->global != r2->global) {
return null_strcmp(r1->identifier, r2->identifier);
}
+static int acl_rights_bsearch_cmp(const void *p1, const void *p2)
+{
+ return acl_rights_cmp(p1, p2);
+}
+
static void
acl_rights_merge(pool_t pool, const char *const **destp, const char *const *src,
bool dup_strings)
if (!array_is_created(&aclobj->rights))
return;
- rights = array_get_modifiable(&aclobj->rights, &count);
- qsort(rights, count, sizeof(*rights), acl_rights_cmp);
+ array_sort(&aclobj->rights, acl_rights_cmp);
/* merge identical identifiers */
+ rights = array_get_modifiable(&aclobj->rights, &count);
for (dest = 0, i = 1; i < count; i++) {
if (acl_rights_cmp(&rights[i], &rights[dest]) == 0) {
/* add i's rights to dest and delete i */
rights = array_get(&aclobj->rights, &count);
if (!bsearch_insert_pos(&update->rights, rights, count, sizeof(*rights),
- acl_rights_cmp, &i))
+ acl_rights_bsearch_cmp, &i))
changed = vfile_object_add_right(aclobj, i, update);
else
changed = vfile_object_modify_right(aclobj, i, update);
const char *username = dict->user->username;
struct dict_iterate_context *iter;
struct dict_transaction_context *dt;
- const char *prefix, *key, *value, **old_ids, *const *new_ids, *p;
+ const char *prefix, *key, *value, *const *old_ids, *const *new_ids, *p;
ARRAY_TYPE(const_string) old_ids_arr;
unsigned int newi, oldi, old_count, new_count;
string_t *path;
}
/* sort the existing identifiers */
- old_ids = array_get_modifiable(&old_ids_arr, &old_count);
- qsort(old_ids, old_count, sizeof(*old_ids), i_strcmp_p);
+ array_sort(&old_ids_arr, i_strcmp_p);
/* sync the identifiers */
path = t_str_new(256);
str_append(path, prefix);
dt = dict_transaction_begin(dict->dict);
+ old_ids = array_get(&old_ids_arr, &old_count);
new_ids = array_get(new_ids_arr, &new_count);
for (newi = oldi = 0; newi < new_count || oldi < old_count; ) {
ret = newi == new_count ? 1 :
}
/* sort identifiers and remove duplicates */
- ids = array_get_modifiable(&ids_arr, &count);
- qsort(ids, count, sizeof(*ids), i_strcmp_p);
+ array_sort(&ids_arr, i_strcmp_p);
+ ids = array_get_modifiable(&ids_arr, &count);
for (i = 1, dest = 0; i < count; i++) {
if (strcmp(ids[dest], ids[i]) != 0) {
if (++dest != i)
seq1, seq2, last_uid);
}
-static int mailbox_name_cmp(const void *p1, const void *p2)
+static int mailbox_name_cmp(const struct fts_orig_mailboxes *box1,
+ const struct fts_orig_mailboxes *box2)
{
- const struct fts_orig_mailboxes *box1 = p1, *box2 = p2;
int ret;
T_BEGIN {
return ret;
}
-static int fts_backend_uid_map_mailbox_cmp(const void *p1, const void *p2)
+static int
+fts_backend_uid_map_mailbox_cmp(const struct fts_backend_uid_map *map1,
+ const struct fts_backend_uid_map *map2)
{
- const struct fts_backend_uid_map *map1 = p1, *map2 = p2;
-
return strcmp(map1->mailbox, map2->mailbox);
}
static int fts_build_init_virtual(struct fts_search_context *fctx)
{
struct fts_search_virtual_context *vctx = &fctx->virtual_ctx;
- struct fts_backend_uid_map *last_uids;
ARRAY_TYPE(mailboxes) mailboxes;
struct mailbox *const *boxes;
- struct fts_orig_mailboxes *orig_boxes;
+ const struct fts_orig_mailboxes *orig_boxes;
struct fts_orig_mailboxes orig_box;
- unsigned int i, box_count, last_uid_count;
+ unsigned int i, box_count;
int ret;
t_array_init(&mailboxes, 64);
array_append(&vctx->orig_mailboxes, &orig_box, 1);
}
- orig_boxes = array_get_modifiable(&vctx->orig_mailboxes, &box_count);
-
+ orig_boxes = array_get(&vctx->orig_mailboxes, &box_count);
if (box_count <= 0) {
if (box_count == 0) {
/* empty virtual mailbox */
pool_unref(&vctx->pool);
return -1;
}
- last_uids = array_get_modifiable(&vctx->last_uids, &last_uid_count);
- qsort(orig_boxes, box_count, sizeof(*orig_boxes), mailbox_name_cmp);
- qsort(last_uids, last_uid_count, sizeof(*last_uids),
- fts_backend_uid_map_mailbox_cmp);
+ array_sort(&vctx->orig_mailboxes, mailbox_name_cmp);
+ array_sort(&vctx->last_uids, fts_backend_uid_map_mailbox_cmp);
ret = fts_build_init_virtual_next(fctx);
return ret < 0 ? -1 : 0;
return FALSE;
}
-static int trash_mailbox_priority_cmp(const void *p1, const void *p2)
+static int trash_mailbox_priority_cmp(const struct trash_mailbox *t1,
+ const struct trash_mailbox *t2)
{
- const struct trash_mailbox *t1 = p1, *t2 = p2;
-
return t1->priority - t2->priority;
}
struct istream *input;
const char *line, *name;
struct trash_mailbox *trash;
- unsigned int count;
int fd, ret = 0;
fd = open(path, O_RDONLY);
i_stream_destroy(&input);
(void)close(fd);
- trash = array_get_modifiable(&tuser->trash_boxes, &count);
- qsort(trash, count, sizeof(*trash), trash_mailbox_priority_cmp);
+ array_sort(&tuser->trash_boxes, trash_mailbox_priority_cmp);
return ret;
}
unsigned int next_record_idx;
};
-static int virtual_search_record_cmp(const void *p1, const void *p2)
+static int virtual_search_record_cmp(const struct virtual_search_record *r1,
+ const struct virtual_search_record *r2)
{
- const struct virtual_search_record *r1 = p1, *r2 = p2;
-
if (r1->mailbox_id < r2->mailbox_id)
return -1;
if (r1->mailbox_id > r2->mailbox_id)
struct virtual_mailbox *mbox =
(struct virtual_mailbox *)ctx->transaction->box;
const struct virtual_mail_index_record *vrec;
- struct virtual_search_record srec, *srecs;
- unsigned int count;
+ struct virtual_search_record srec;
const void *data;
bool expunged;
int ret, result;
}
mail_search_args_reset(ctx->args->args, FALSE);
}
- srecs = array_get_modifiable(&vctx->records, &count);
- qsort(srecs, count, sizeof(*srecs), virtual_search_record_cmp);
+ array_sort(&vctx->records, virtual_search_record_cmp);
- ctx->progress_max = count;
+ ctx->progress_max = array_count(&vctx->records);
return ret;
}
}
}
-static int bbox_mailbox_id_cmp(const void *p1, const void *p2)
+static int bbox_mailbox_id_cmp(struct virtual_backend_box *const *b1,
+ struct virtual_backend_box *const *b2)
{
- const struct virtual_backend_box *const *b1 = p1, *const *b2 = p2;
-
if ((*b1)->mailbox_id < (*b2)->mailbox_id)
return -1;
if ((*b1)->mailbox_id > (*b2)->mailbox_id)
}
}
/* sort the backend mailboxes by mailbox_id. */
- qsort(bboxes, count, sizeof(*bboxes), bbox_mailbox_id_cmp);
+ array_sort(&ctx->mbox->backend_boxes, bbox_mailbox_id_cmp);
return ret;
}
}
}
-static int virtual_backend_uidmap_cmp(const void *p1, const void *p2)
+static int virtual_backend_uidmap_cmp(const struct virtual_backend_uidmap *u1,
+ const struct virtual_backend_uidmap *u2)
{
- const struct virtual_backend_uidmap *u1 = p1, *u2 = p2;
-
if (u1->real_uid < u2->real_uid)
return -1;
if (u1->real_uid > u2->real_uid)
static void virtual_sync_bbox_uids_sort(struct virtual_backend_box *bbox)
{
- struct virtual_backend_uidmap *uids;
- unsigned int uid_count;
-
/* the uidmap must be sorted by real_uids */
- uids = array_get_modifiable(&bbox->uids, &uid_count);
- qsort(uids, uid_count, sizeof(*uids), virtual_backend_uidmap_cmp);
+ array_sort(&bbox->uids, virtual_backend_uidmap_cmp);
bbox->uids_nonsorted = FALSE;
}
}
}
-static int virtual_add_record_cmp(const void *p1, const void *p2)
+static int virtual_add_record_cmp(const struct virtual_add_record *add1,
+ const struct virtual_add_record *add2)
{
- const struct virtual_add_record *add1 = p1, *add2 = p2;
-
if (add1->received_date < add2->received_date)
return -1;
if (add1->received_date > add2->received_date)
}
}
- qsort(adds, count, sizeof(*adds), virtual_add_record_cmp);
+ array_sort(&ctx->all_adds, virtual_add_record_cmp);
}
static void virtual_sync_backend_add_new(struct virtual_sync_context *ctx)