libosmocore  0.9.0
Osmocom core library
General-purpose utility functions

Files

file  defs.h
 General definitions that are meant to be included from header files.
 
file  panic.h
 
file  utils.h
 
file  panic.c
 
file  utils.c
 

Data Structures

struct  value_string
 A mapping between human-readable string and numeric value. More...
 

Macros

#define OSMO_GNUC_PREREQ(maj, min)   0
 Check for gcc and version. More...
 
#define OSMO_DEPRECATED(text)
 Set the deprecated attribute with a message.
 
#define ARRAY_SIZE(x)   (sizeof(x) / sizeof((x)[0]))
 Determine number of elements in an array of static size.
 
#define OSMO_MAX(a, b)   ((a) >= (b) ? (a) : (b))
 Return the maximum of two specified values.
 
#define OSMO_MIN(a, b)   ((a) >= (b) ? (b) : (a))
 Return the minimum of two specified values.
 
#define osmo_static_assert(exp, name)   typedef int dummy##name [(exp) ? 1 : -1] __attribute__((__unused__));
 
#define OSMO_SNPRINTF_RET(ret, rem, offset, len)
 
#define OSMO_ASSERT(exp)
 

Typedefs

typedef void(* osmo_panic_handler_t) (const char *fmt, va_list args)
 panic handler callback function type
 

Functions

void osmo_panic (const char *fmt,...)
 Terminate the current program with a panic.
 
void osmo_set_panic_handler (osmo_panic_handler_t h)
 Set the panic handler.
 
const char * get_value_string (const struct value_string *vs, uint32_t val)
 get human-readable string for given value More...
 
int get_string_value (const struct value_string *vs, const char *str)
 get numeric value for given human-readable string More...
 
char osmo_bcd2char (uint8_t bcd)
 Convert BCD-encoded digit into printable character. More...
 
uint8_t osmo_char2bcd (char c)
 Convert number in ASCII to BCD value. More...
 
int osmo_hexparse (const char *str, uint8_t *b, int max_len)
 Parse a string ocntaining hexadecimal digits. More...
 
char * osmo_ubit_dump (const uint8_t *bits, unsigned int len)
 Convert a sequence of unpacked bits to ASCII string. More...
 
char * osmo_hexdump (const unsigned char *buf, int len)
 Convert binary sequence to hexadecimal ASCII string. More...
 
char * osmo_hexdump_nospc (const unsigned char *buf, int len)
 Convert binary sequence to hexadecimal ASCII string. More...
 
char * osmo_osmo_hexdump_nospc (const unsigned char *buf, int len) __attribute__((__deprecated__))
 
void osmo_str2lower (char *out, const char *in)
 Convert an entire string to lower case. More...
 
void osmo_str2upper (char *out, const char *in)
 Convert an entire string to upper case. More...
 
static void osmo_talloc_replace_string (void *ctx, char **dst, char *newstr)
 
static void osmo_panic_default (const char *fmt, va_list args)
 
static char * _osmo_hexdump (const unsigned char *buf, int len, char *delim)
 
char alias ("osmo_hexdump_nospc")))
 

Variables

static osmo_panic_handler_t osmo_panic_handler = (void*)0
 
static char namebuf [255]
 
static char hexd_buff [4096]
 
static const char hex_chars [] = "0123456789abcdef"
 

Detailed Description

Macro Definition Documentation

#define OSMO_ASSERT (   exp)
Value:
if (!(exp)) { \
fprintf(stderr, "Assert failed %s %s:%d\n", #exp, __FILE__, __LINE__); \
abort(); \
}
void osmo_generate_backtrace(void)
Generate and print a call back-trace.
Definition: backtrace.c:67
#define OSMO_GNUC_PREREQ (   maj,
  min 
)    0

Check for gcc and version.

Note
Albeit glibc provides a features.h file that contains a similar definition (__GNUC_PREREQ), this definition has been copied from there to have it available with other libraries, too.
Returns
!= 0 iff gcc is used and it's version is at least maj.min.
#define OSMO_SNPRINTF_RET (   ret,
  rem,
  offset,
  len 
)
Value:
do { \
len += ret; \
if (ret > rem) \
ret = rem; \
offset += ret; \
rem -= ret; \
} while (0)
uint16_t len
length of bytes used in msgb
Definition: msgb.h:62

Function Documentation

int get_string_value ( const struct value_string vs,
const char *  str 
)

get numeric value for given human-readable string

Parameters
[in]vsArray of value_string tuples
[in]strhuman-readable string
Returns
numeric value (>0) or negative numer in case of error

References value_string::value.

Referenced by log_parse_level().

const char * get_value_string ( const struct value_string vs,
uint32_t  val 
)

get human-readable string for given value

Parameters
[in]vsArray of value_string tuples
[in]valValue to be converted
Returns
pointer to human-readable string

References value_string::str.

Referenced by log_level_str().

char osmo_bcd2char ( uint8_t  bcd)

Convert BCD-encoded digit into printable character.

Parameters
[in]bcdA single BCD-encoded digit
Returns
single printable character
uint8_t osmo_char2bcd ( char  c)

Convert number in ASCII to BCD value.

Parameters
[in]cASCII character
Returns
BCD encoded value of character
char * osmo_hexdump ( const unsigned char *  buf,
int  len 
)

Convert binary sequence to hexadecimal ASCII string.

Parameters
[in]bufpointer to sequence of bytes
[in]lenlength of buf in number of bytes
Returns
pointer to zero-terminated string

This function will print a sequence of bytes as hexadecimal numbers, adding one space character between each byte (e.g. "1a ef d9")

Referenced by msgb_hexdump().

char * osmo_hexdump_nospc ( const unsigned char *  buf,
int  len 
)

Convert binary sequence to hexadecimal ASCII string.

Parameters
[in]bufpointer to sequence of bytes
[in]lenlength of buf in number of bytes
Returns
pointer to zero-terminated string

This function will print a sequence of bytes as hexadecimal numbers, without any space character between each byte (e.g. "1aefd9")

int osmo_hexparse ( const char *  str,
uint8_t *  b,
int  max_len 
)

Parse a string ocntaining hexadecimal digits.

Parameters
[in]strstring containing ASCII encoded hexadecimal digits
[out]boutput buffer
[in]max_lenmaximum space in output buffer
Returns
number of parsed octets, or -1 on error
void osmo_str2lower ( char *  out,
const char *  in 
)

Convert an entire string to lower case.

Parameters
[out]outoutput string, caller-allocated
[in]ininput string
void osmo_str2upper ( char *  out,
const char *  in 
)

Convert an entire string to upper case.

Parameters
[out]outoutput string, caller-allocated
[in]ininput string
char * osmo_ubit_dump ( const uint8_t *  bits,
unsigned int  len 
)

Convert a sequence of unpacked bits to ASCII string.

Parameters
[in]bitsA sequence of unpacked bits
[in]lenLength of bits