blob: 32c318c3506431599c9c8b5f7b5cb4827b6eea41 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
/* SPDX-License-Identifier: BSD-3-Clause */
#include <inttypes.h>
#include <string.h>
#include <strings.h>
#include <valstr.h>
const char *val2str_default(uint32_t val, const struct valstr *vs,
const char *def_str)
{
int i;
for (i = 0; vs[i].str; i++) {
if (vs[i].val == val)
return vs[i].str;
}
return def_str;
}
const char *val2str(uint32_t val, const struct valstr *vs)
{
return val2str_default(val, vs, "Unknown");
}
uint32_t str2val(const char *str, const struct valstr *vs)
{
int i;
for (i = 0; vs[i].str; i++) {
if (strcasecmp(vs[i].str, str) == 0)
return vs[i].val;
}
return vs[i].val;
}
|