summaryrefslogtreecommitdiffstats
path: root/lib/log.c
diff options
context:
space:
mode:
authorTom Grennan <tgrennan@vyatta.com>2008-04-10 21:56:49 +0000
committerTom Grennan <tgrennan@vyatta.com>2008-04-10 21:56:49 +0000
commitc1bdabf8dd2f22a33fdc35b70b93e871f179445d (patch)
tree570e66e842fc556fc643e97aa37e0183ded19f56 /lib/log.c
parentdb59fcc9e02b5755a92e4d2913420c1e09e05517 (diff)
parent9334b80b2c84f33d0d749b4a172f1d87a77a8544 (diff)
downloadquagga-c1bdabf8dd2f22a33fdc35b70b93e871f179445d.tar.bz2
quagga-c1bdabf8dd2f22a33fdc35b70b93e871f179445d.tar.xz
Merge branch 'upstream' into hollywood
Conflicts: ChangeLog zebra/zebra_rib.c
Diffstat (limited to 'lib/log.c')
-rw-r--r--lib/log.c29
1 files changed, 21 insertions, 8 deletions
diff --git a/lib/log.c b/lib/log.c
index ff47cae0..ce00bfbb 100644
--- a/lib/log.c
+++ b/lib/log.c
@@ -752,14 +752,24 @@ lookup (struct message *mes, int key)
}
/* Older/faster version of message lookup function, but requires caller to pass
- in the array size (instead of relying on a 0 key to terminate the search). */
+ * in the array size (instead of relying on a 0 key to terminate the search).
+ *
+ * The return value is the message string if found, or the 'none' pointer
+ * provided otherwise.
+ */
const char *
-mes_lookup (struct message *meslist, int max, int index)
+mes_lookup (struct message *meslist, int max, int index, const char *none)
{
+ int pos = index - meslist[0].key;
+
/* first check for best case: index is in range and matches the key
- value in that slot */
- if ((index >= 0) && (index < max) && (meslist[index].key == index))
- return meslist[index].str;
+ * value in that slot.
+ * NB: key numbering might be offset from 0. E.g. protocol constants
+ * often start at 1.
+ */
+ if ((pos >= 0) && (pos < max)
+ && (meslist[pos].key == index))
+ return meslist[pos].str;
/* fall back to linear search */
{
@@ -769,14 +779,17 @@ mes_lookup (struct message *meslist, int max, int index)
{
if (meslist->key == index)
{
+ const char *str = (meslist->str ? meslist->str : none);
+
zlog_debug ("message index %d [%s] found in position %d (max is %d)",
- index, meslist->str, i, max);
- return meslist->str;
+ index, str, i, max);
+ return str;
}
}
}
zlog_err("message index %d not found (max is %d)", index, max);
- return NULL;
+ assert (none);
+ return none;
}
/* Wrapper around strerror to handle case where it returns NULL. */