From 476c0da5319b155e0f4abec2b1fe6bc0c1fb6df7 Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Fri, 20 Feb 2009 18:09:12 +0100 Subject: [PATCH] Logging: Introduce LS_NUM_TYPES and use it. --- ucw/log-stream.c | 8 ++++---- ucw/log.h | 2 ++ 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/ucw/log-stream.c b/ucw/log-stream.c index 8b697f8b..5af9f3e6 100644 --- a/ucw/log-stream.c +++ b/ucw/log-stream.c @@ -176,14 +176,14 @@ int log_register_type(const char *name) { if (!log_type_names) { - log_type_names = xmalloc_zero(LS_GET_TYPE(~0U) * sizeof(char *)); + log_type_names = xmalloc_zero(LS_NUM_TYPES * sizeof(char *)); log_type_names[0] = "default"; } uns id; - for (id=0; id < LS_GET_TYPE(~0U) && log_type_names[id]; id++) + for (id=0; id < LS_NUM_TYPES && log_type_names[id]; id++) if (!strcmp(log_type_names[id], name)) return LS_SET_TYPE(id); - ASSERT(id < LS_GET_TYPE(~0U)); + ASSERT(id < LS_NUM_TYPES); log_type_names[id] = xstrdup(name); return LS_SET_TYPE(id); } @@ -196,7 +196,7 @@ int log_find_type(const char *name) if (!log_type_names) return -1; - for (uns id=0; id < LS_GET_TYPE(~0U) && log_type_names[id]; id++) + for (uns id=0; id < LS_NUM_TYPES && log_type_names[id]; id++) if (!strcmp(log_type_names[id], name)) return LS_SET_TYPE(id); return -1; diff --git a/ucw/log.h b/ucw/log.h index 14134111..cd32f83e 100644 --- a/ucw/log.h +++ b/ucw/log.h @@ -111,6 +111,8 @@ enum ls_flagmasks { // Bit masks of groups #define LS_SET_TYPE(type) ((type) << LS_TYPE_POS) /** Convert message type to flags **/ #define LS_SET_CTRL(ctrl) ((ctrl) << LS_CTRL_POS) /** Convert control bits to flags **/ +#define LS_NUM_TYPES (1 << LS_TYPE_BITS) + /** Register a new message type and return the corresponding flag set (encoded by `LS_SET_TYPE`). **/ int log_register_type(const char *name); -- 2.39.2