Merge commit 'fdd0a700930bdd04bc8827ef88dc5039ecc5b6ce'
[osmocom-bb.git] / src / shared / libosmocore / src / utils.c
1
2 #include <string.h>
3 #include <stdint.h>
4 #include <errno.h>
5
6 #include <osmocore/utils.h>
7
8 const 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
21 int 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 }