diff options
author | Harald Welte <laforge@gnumonks.org> | 2010-07-12 09:21:13 +0200 |
---|---|---|
committer | Harald Welte <laforge@gnumonks.org> | 2010-07-12 09:21:13 +0200 |
commit | 298b361b133a54f3b7c39d168e5028e69e736113 (patch) | |
tree | e09b86a6c6463bc1cbc032afd4bcf2eea02207ab /src/shared/libosmocore/src/utils.c | |
parent | 231444b548df8aff616f314ebc6135588b0ffec3 (diff) | |
parent | ed00fe4449ac2309ad80c32f0ba7aa80b2b8895a (diff) |
Add 'src/shared/libosmocore/' from commit 'ed00fe4449ac2309ad80c32f0ba7aa80b2b8895a'
git-subtree-dir: src/shared/libosmocore
git-subtree-mainline: 231444b548df8aff616f314ebc6135588b0ffec3
git-subtree-split: ed00fe4449ac2309ad80c32f0ba7aa80b2b8895a
Diffstat (limited to 'src/shared/libosmocore/src/utils.c')
-rw-r--r-- | src/shared/libosmocore/src/utils.c | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/src/shared/libosmocore/src/utils.c b/src/shared/libosmocore/src/utils.c new file mode 100644 index 00000000..4dab0645 --- /dev/null +++ b/src/shared/libosmocore/src/utils.c @@ -0,0 +1,50 @@ + +#include <string.h> +#include <stdint.h> +#include <errno.h> +#include <stdio.h> + +#include <osmocore/utils.h> + +static char namebuf[255]; +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; + } + + snprintf(namebuf, sizeof(namebuf), "unknown 0x%x", val); + return namebuf; +} + +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; +} + +char bcd2char(uint8_t bcd) +{ + if (bcd < 0xa) + return '0' + bcd; + else + return 'A' + (bcd - 0xa); +} + +/* only works for numbers in ascci */ +uint8_t char2bcd(char c) +{ + return c - 0x30; +} |