Import value_string utilities and some RSL stuff from OpenBSC
[osmocom-bb.git] / src / utils.c
diff --git a/src/utils.c b/src/utils.c
new file mode 100644 (file)
index 0000000..0d878c7
--- /dev/null
@@ -0,0 +1,32 @@
+
+#include <string.h>
+#include <stdint.h>
+#include <errno.h>
+
+#include <osmocore/utils.h>
+
+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;
+}