forked from wdoekes/asterisk-chan-dongle
-
Notifications
You must be signed in to change notification settings - Fork 1
/
mutils.h
45 lines (36 loc) · 978 Bytes
/
mutils.h
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
38
39
40
41
42
43
44
45
/*
Copyright (C) 2010,2011 bg <[email protected]>
*/
#ifndef CHAN_DONGLE_MUTILS_H_INCLUDED
#define CHAN_DONGLE_MUTILS_H_INCLUDED
#include "export.h"
#include <string.h>
#define ITEMS_OF(x) (sizeof(x)/sizeof((x)[0]))
#define STRLEN(string) (sizeof(string)-1)
#ifndef MIN
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
#endif
INLINE_DECL const char * enum2str_def(unsigned value, const char * const names[], unsigned items, const char * def)
{
const char * name;
if(value < items)
name = names[value];
else
name = def;
return name;
}
INLINE_DECL const char * enum2str(unsigned value, const char * const names[], unsigned items)
{
return enum2str_def(value, names, items, "unknown");
}
INLINE_DECL int str2enum(const char * value, const char * const options[], unsigned items)
{
unsigned index;
for(index = 0; index < items; index++)
{
if(strcasecmp(value, options[index]) == 0)
return index;
}
return -1;
}
#endif /* CHAN_DONGLE_MUTILS_H_INCLUDED */