Harald Welte | ec8b450 | 2010-02-20 20:34:29 +0100 | [diff] [blame] | 1 | #ifndef OSMOCORE_UTIL_H |
| 2 | #define OSMOCORE_UTIL_H |
| 3 | |
| 4 | #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) |
| 5 | |
Harald Welte | d284cd9 | 2010-03-01 21:58:31 +0100 | [diff] [blame] | 6 | #include <stdint.h> |
| 7 | |
| 8 | struct value_string { |
| 9 | unsigned int value; |
| 10 | const char *str; |
| 11 | }; |
| 12 | |
| 13 | const char *get_value_string(const struct value_string *vs, uint32_t val); |
| 14 | int get_string_value(const struct value_string *vs, const char *str); |
| 15 | |
Pablo Neira Ayuso | 87f7b25 | 2011-05-07 12:43:08 +0200 | [diff] [blame] | 16 | char osmo_bcd2char(uint8_t bcd); |
Harald Welte | a73e2f9 | 2010-03-04 10:50:32 +0100 | [diff] [blame] | 17 | /* only works for numbers in ascci */ |
Pablo Neira Ayuso | 87f7b25 | 2011-05-07 12:43:08 +0200 | [diff] [blame] | 18 | uint8_t osmo_char2bcd(char c); |
Harald Welte | d284cd9 | 2010-03-01 21:58:31 +0100 | [diff] [blame] | 19 | |
Pablo Neira Ayuso | 87f7b25 | 2011-05-07 12:43:08 +0200 | [diff] [blame] | 20 | int osmo_hexparse(const char *str, uint8_t *b, int max_len); |
| 21 | char *osmo_hexdump(const unsigned char *buf, int len); |
| 22 | char *osmo_osmo_hexdump_nospc(const unsigned char *buf, int len); |
| 23 | char *osmo_ubit_dump(const uint8_t *bits, unsigned int len); |
Harald Welte | 3eba991 | 2010-07-30 10:37:29 +0200 | [diff] [blame] | 24 | |
Pablo Neira Ayuso | 87f7b25 | 2011-05-07 12:43:08 +0200 | [diff] [blame] | 25 | #define osmo_static_assert(exp, name) typedef int dummy##name [(exp) ? 1 : -1]; |
Holger Hans Peter Freyther | 52c07ca | 2011-01-16 17:37:27 +0100 | [diff] [blame] | 26 | |
Harald Welte | 2822296 | 2011-02-18 20:37:04 +0100 | [diff] [blame] | 27 | void osmo_str2lower(char *out, const char *in); |
| 28 | void osmo_str2upper(char *out, const char *in); |
| 29 | |
Pablo Neira Ayuso | 3abad6a | 2011-03-28 19:24:22 +0200 | [diff] [blame] | 30 | #define OSMO_SNPRINTF_RET(ret, rem, offset, len) \ |
| 31 | do { \ |
| 32 | len += ret; \ |
| 33 | if (ret > rem) \ |
| 34 | ret = rem; \ |
| 35 | offset += ret; \ |
| 36 | rem -= ret; \ |
| 37 | } while (0) |
| 38 | |
Harald Welte | ec8b450 | 2010-02-20 20:34:29 +0100 | [diff] [blame] | 39 | #endif |