From d284cd9f43a6954be338d85470a17ac6796b56d5 Mon Sep 17 00:00:00 2001 From: Harald Welte Date: Mon, 1 Mar 2010 21:58:31 +0100 Subject: Import value_string utilities and some RSL stuff from OpenBSC --- src/utils.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/utils.c (limited to 'src/utils.c') diff --git a/src/utils.c b/src/utils.c new file mode 100644 index 00000000..0d878c7b --- /dev/null +++ b/src/utils.c @@ -0,0 +1,32 @@ + +#include +#include +#include + +#include + +const char *get_value_string(const struct value_string *vs, uint32_t val) +{ + int i; + + for (i = 0;; i++) { + if (vs[i].value == 0 && vs[i].str == NULL) + break; + if (vs[i].value == val) + return vs[i].str; + } + return "unknown"; +} + +int get_string_value(const struct value_string *vs, const char *str) +{ + int i; + + for (i = 0;; i++) { + if (vs[i].value == 0 && vs[i].str == NULL) + break; + if (!strcasecmp(vs[i].str, str)) + return vs[i].value; + } + return -EINVAL; +} -- cgit v1.2.3