blob: 0d878c7b1fb73fa07562a5dd01c4e6073f624b76 [file] [log] [blame]
Harald Welted284cd92010-03-01 21:58:31 +01001
2#include <string.h>
3#include <stdint.h>
4#include <errno.h>
5
6#include <osmocore/utils.h>
7
8const char *get_value_string(const struct value_string *vs, uint32_t val)
9{
10 int i;
11
12 for (i = 0;; i++) {
13 if (vs[i].value == 0 && vs[i].str == NULL)
14 break;
15 if (vs[i].value == val)
16 return vs[i].str;
17 }
18 return "unknown";
19}
20
21int get_string_value(const struct value_string *vs, const char *str)
22{
23 int i;
24
25 for (i = 0;; i++) {
26 if (vs[i].value == 0 && vs[i].str == NULL)
27 break;
28 if (!strcasecmp(vs[i].str, str))
29 return vs[i].value;
30 }
31 return -EINVAL;
32}