Mercurial > dovecot > original-hg > dovecot-1.2
changeset 6494:59490181469e HEAD
Use N_ELEMENTS() macro instead of doing sizeof()/sizeof([0]) ourself.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Mon, 24 Sep 2007 20:27:16 +0300 |
parents | 2821a472806f |
children | 94501a17dcd0 |
files | src/deliver/mail-send.c src/imap/commands.c src/imap/imap-fetch.c src/lib-index/mail-index-transaction.c src/lib-otp/otp-hash.c src/lib-storage/index/mbox/mbox-md5.c src/lib-storage/index/mbox/mbox-storage.c src/lib-storage/index/mbox/mbox-sync-parse.c src/lib/backtrace-string.c src/lib/ioloop-notify-kqueue.c src/lib/primes.c src/master/capabilities-posix.c src/master/ssl-init-openssl.c src/plugins/quota/quota.c |
diffstat | 14 files changed, 22 insertions(+), 38 deletions(-) [+] |
line wrap: on
line diff
--- a/src/deliver/mail-send.c Mon Sep 24 20:17:59 2007 +0300 +++ b/src/deliver/mail-send.c Mon Sep 24 20:27:16 2007 +0300 @@ -131,7 +131,7 @@ input = i_stream_create_header_filter(input, HEADER_FILTER_EXCLUDE | HEADER_FILTER_NO_CR | HEADER_FILTER_HIDE_BODY, exclude_headers, - sizeof(exclude_headers) / sizeof(exclude_headers[0]), + N_ELEMENTS(exclude_headers), null_header_filter_callback, NULL); while ((ret = i_stream_read_data(input, &data, &size, 0)) > 0) { @@ -170,8 +170,7 @@ input = i_stream_create_header_filter(input, HEADER_FILTER_EXCLUDE | HEADER_FILTER_NO_CR, hide_headers, - sizeof(hide_headers) / - sizeof(hide_headers[0]), + N_ELEMENTS(hide_headers), null_header_filter_callback, NULL); while ((ret = i_stream_read_data(input, &data, &size, 0)) > 0) {
--- a/src/imap/commands.c Mon Sep 24 20:17:59 2007 +0300 +++ b/src/imap/commands.c Mon Sep 24 20:27:16 2007 +0300 @@ -38,8 +38,7 @@ { "UID SEARCH", cmd_search, COMMAND_FLAG_BREAKS_SEQS }, { "UID STORE", cmd_store, COMMAND_FLAG_BREAKS_SEQS } }; -#define IMAP4REV1_COMMANDS_COUNT \ - (sizeof(imap4rev1_commands) / sizeof(imap4rev1_commands[0])) +#define IMAP4REV1_COMMANDS_COUNT N_ELEMENTS(imap4rev1_commands) const struct command imap_ext_commands[] = { { "IDLE", cmd_idle, COMMAND_FLAG_BREAKS_SEQS }, @@ -52,8 +51,7 @@ { "UNSELECT", cmd_unselect, COMMAND_FLAG_BREAKS_MAILBOX }, { "X-CANCEL", cmd_x_cancel, 0 } }; -#define IMAP_EXT_COMMANDS_COUNT \ - (sizeof(imap_ext_commands) / sizeof(imap_ext_commands[0])) +#define IMAP_EXT_COMMANDS_COUNT N_ELEMENTS(imap_ext_commands) static ARRAY_DEFINE(commands, struct command); static bool commands_unsorted;
--- a/src/imap/imap-fetch.c Mon Sep 24 20:17:59 2007 +0300 +++ b/src/imap/imap-fetch.c Mon Sep 24 20:27:16 2007 +0300 @@ -86,8 +86,7 @@ if (fetch_handlers == NULL) { imap_fetch_handlers_register(default_handlers, - sizeof(default_handlers) / - sizeof(default_handlers[0])); + N_ELEMENTS(default_handlers)); } ctx = p_new(cmd->pool, struct imap_fetch_context, 1);
--- a/src/lib-index/mail-index-transaction.c Mon Sep 24 20:17:59 2007 +0300 +++ b/src/lib-index/mail-index-transaction.c Mon Sep 24 20:27:16 2007 +0300 @@ -299,8 +299,7 @@ { struct mail_index_header hdr; const struct mail_index_record *rec; - const int max_days = - sizeof(hdr.day_first_uid) / sizeof(hdr.day_first_uid[0]); + const int max_days = N_ELEMENTS(hdr.day_first_uid); struct tm tm; time_t stamp; int i, days;
--- a/src/lib-otp/otp-hash.c Mon Sep 24 20:17:59 2007 +0300 +++ b/src/lib-otp/otp-hash.c Mon Sep 24 20:27:16 2007 +0300 @@ -87,22 +87,20 @@ { "sha1", F(sha1_init), F(sha1_loop), F(sha1_result), F(sha1_fold) }, }; -#define N_DIGESTS (int)(sizeof(digests) / sizeof(digests[0])) - #undef F const char *digest_name(unsigned int algo) { - i_assert(algo < N_DIGESTS); + i_assert(algo < N_ELEMENTS(digests)); return digests[algo].name; } int digest_find(const char *name) { - int i; + unsigned int i; - for (i = 0; i < N_DIGESTS; i++) + for (i = 0; i < N_ELEMENTS(digests); i++) if (strcmp(name, digests[i].name) == 0) return i; @@ -111,7 +109,7 @@ int digest_init(struct digest_context *ctx, const unsigned int algo) { - i_assert(algo < N_DIGESTS); + i_assert(algo < N_ELEMENTS(digests)); ctx->digest = digests + algo; ctx->digest->init((void *) &ctx->ctx);
--- a/src/lib-storage/index/mbox/mbox-md5.c Mon Sep 24 20:17:59 2007 +0300 +++ b/src/lib-storage/index/mbox/mbox-md5.c Mon Sep 24 20:27:16 2007 +0300 @@ -76,8 +76,6 @@ { "Received", parse_received }, { "X-Delivery-ID", parse_x_delivery_id } }; -#define MD5_HEADER_FUNCS_COUNT \ - (sizeof(md5_header_funcs) / sizeof(*md5_header_funcs)) static int bsearch_header_func_cmp(const void *p1, const void *p2) { @@ -102,7 +100,7 @@ struct mbox_md5_header_func *func; func = bsearch(hdr->name, md5_header_funcs, - MD5_HEADER_FUNCS_COUNT, sizeof(*md5_header_funcs), + N_ELEMENTS(md5_header_funcs), sizeof(*md5_header_funcs), bsearch_header_func_cmp); if (func != NULL) (void)func->func(ctx, hdr);
--- a/src/lib-storage/index/mbox/mbox-storage.c Mon Sep 24 20:17:59 2007 +0300 +++ b/src/lib-storage/index/mbox/mbox-storage.c Mon Sep 24 20:27:16 2007 +0300 @@ -47,8 +47,7 @@ "X-Status", "X-UID" }; -unsigned int mbox_hide_headers_count = - sizeof(mbox_hide_headers) / sizeof(mbox_hide_headers[0]); +unsigned int mbox_hide_headers_count = N_ELEMENTS(mbox_hide_headers); /* A bit ugly duplification of the above list. It's safe to modify this list without bad side effects, just keep the list sorted. */ @@ -62,8 +61,7 @@ "X-Status", "X-UID" }; -unsigned int mbox_save_drop_headers_count = - sizeof(mbox_save_drop_headers) / sizeof(mbox_save_drop_headers[0]); +unsigned int mbox_save_drop_headers_count = N_ELEMENTS(mbox_save_drop_headers); extern struct mail_storage mbox_storage; extern struct mailbox mbox_mailbox;
--- a/src/lib-storage/index/mbox/mbox-sync-parse.c Mon Sep 24 20:17:59 2007 +0300 +++ b/src/lib-storage/index/mbox/mbox-sync-parse.c Mon Sep 24 20:27:16 2007 +0300 @@ -427,7 +427,6 @@ { "X-Status", parse_x_status }, { "X-UID", parse_x_uid } }; -#define HEADER_FUNCS_COUNT (sizeof(header_funcs) / sizeof(*header_funcs)) static int mbox_sync_bsearch_header_func_cmp(const void *p1, const void *p2) { @@ -477,7 +476,7 @@ } func = bsearch(hdr->name, header_funcs, - HEADER_FUNCS_COUNT, sizeof(*header_funcs), + N_ELEMENTS(header_funcs), sizeof(*header_funcs), mbox_sync_bsearch_header_func_cmp); if (func != NULL) { @@ -559,7 +558,7 @@ break; func = bsearch(hdr->name, header_funcs, - HEADER_FUNCS_COUNT, sizeof(*header_funcs), + N_ELEMENTS(header_funcs), sizeof(*header_funcs), mbox_sync_bsearch_header_func_cmp); if (func != NULL) { if (strcasecmp(hdr->name, "X-UID") == 0) {
--- a/src/lib/backtrace-string.c Mon Sep 24 20:17:59 2007 +0300 +++ b/src/lib/backtrace-string.c Mon Sep 24 20:27:16 2007 +0300 @@ -18,7 +18,7 @@ char **strings; int ret, i; - ret = backtrace(stack, sizeof(stack)/sizeof(stack[0])); + ret = backtrace(stack, N_ELEMENTS(stack)); if (ret <= STACK_SKIP_COUNT) return -1;
--- a/src/lib/ioloop-notify-kqueue.c Mon Sep 24 20:17:59 2007 +0300 +++ b/src/lib/ioloop-notify-kqueue.c Mon Sep 24 20:27:16 2007 +0300 @@ -49,8 +49,7 @@ ts.tv_sec = 0; ts.tv_nsec = 0; - ret = kevent(ctx->kq, NULL, 0, events, - sizeof(events)/sizeof(events[0]), &ts); + ret = kevent(ctx->kq, NULL, 0, events, N_ELEMENTS(events), &ts); if (ret <= 0) { if (ret == 0 || errno == EINTR) return;
--- a/src/lib/primes.c Mon Sep 24 20:17:59 2007 +0300 +++ b/src/lib/primes.c Mon Sep 24 20:27:16 2007 +0300 @@ -38,7 +38,7 @@ 13845163 }; -static const unsigned int primes_count = sizeof(primes) / sizeof(primes[0]); +static const unsigned int primes_count = N_ELEMENTS(primes); unsigned int primes_closest(unsigned int num) {
--- a/src/master/capabilities-posix.c Mon Sep 24 20:17:59 2007 +0300 +++ b/src/master/capabilities-posix.c Mon Sep 24 20:27:16 2007 +0300 @@ -22,9 +22,9 @@ caps = cap_init(); cap_clear(caps); cap_set_flag(caps, CAP_PERMITTED, - sizeof(suidcaps) / sizeof(cap_value_t), suidcaps, CAP_SET); + N_ELEMENTS(suidcaps), suidcaps, CAP_SET); cap_set_flag(caps, CAP_EFFECTIVE, - sizeof(suidcaps) / sizeof(cap_value_t), suidcaps, CAP_SET); + N_ELEMENTS(suidcaps), suidcaps, CAP_SET); cap_set_proc(caps); cap_free(caps); }
--- a/src/master/ssl-init-openssl.c Mon Sep 24 20:17:59 2007 +0300 +++ b/src/master/ssl-init-openssl.c Mon Sep 24 20:27:16 2007 +0300 @@ -14,8 +14,6 @@ #define DH_GENERATOR 2 static int dh_param_bitsizes[] = { 512, 1024 }; -#define DH_PARAM_BITSIZE_COUNT \ - (sizeof(dh_param_bitsizes)/sizeof(dh_param_bitsizes[0])) static const char *ssl_last_error(void) { @@ -63,7 +61,7 @@ unsigned int i; int bits; - for (i = 0; i < DH_PARAM_BITSIZE_COUNT; i++) + for (i = 0; i < N_ELEMENTS(dh_param_bitsizes); i++) generate_dh_parameters(dh_param_bitsizes[i], fd, fname); bits = 0; if (write_full(fd, &bits, sizeof(bits)) < 0)
--- a/src/plugins/quota/quota.c Mon Sep 24 20:17:59 2007 +0300 +++ b/src/plugins/quota/quota.c Mon Sep 24 20:27:16 2007 +0300 @@ -35,7 +35,6 @@ "a_backend_dirsize, "a_backend_maildir }; -#define QUOTA_CLASS_COUNT (sizeof(quota_backends)/sizeof(quota_backends[0])) static int quota_default_test_alloc(struct quota_transaction_context *ctx, uoff_t size, bool *too_large_r); @@ -74,7 +73,7 @@ { unsigned int i; - for (i = 0; i < QUOTA_CLASS_COUNT; i++) { + for (i = 0; i < N_ELEMENTS(quota_backends); i++) { if (strcmp(quota_backends[i]->name, name) == 0) return quota_backends[i]; }