GNU Radio's GSM Package
General-purpose utility functions

Files

file  defs.h
 
file  panic.h
 
file  utils.h
 

Classes

struct  value_string
 

Macros

#define OSMO_GNUC_PREREQ(maj, min)   0
 
#define OSMO_DEPRECATED(text)
 
#define OSMO_DEPRECATED_OUTSIDE_LIBOSMOCORE   OSMO_DEPRECATED("For internal use inside libosmocore only.")
 
#define ARRAY_SIZE(x)   (sizeof(x) / sizeof((x)[0]))
 
#define OSMO_MAX(a, b)   ((a) >= (b) ? (a) : (b))
 
#define OSMO_MIN(a, b)   ((a) >= (b) ? (b) : (a))
 
#define OSMO_STRINGIFY(x)   #x
 
#define OSMO_STRINGIFY_VAL(x)   OSMO_STRINGIFY(x)
 
#define OSMO_VALUE_STRING(x)   { x, #x }
 
#define OSMO_BYTES_FOR_BITS(BITS)   ((BITS + 8 - 1) / 8)
 
#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)
 

Functions

void osmo_panic (const char *fmt,...)
 
void osmo_set_panic_handler (osmo_panic_handler_t h)
 
const char * get_value_string_or_null (const struct value_string *vs, uint32_t val)
 
int get_string_value (const struct value_string *vs, const char *str)
 
char osmo_bcd2char (uint8_t bcd)
 
uint8_t osmo_char2bcd (char c)
 
char * osmo_ubit_dump (const uint8_t *bits, unsigned int len)
 
char * osmo_hexdump (const unsigned char *buf, int len)
 
char * osmo_hexdump_nospc (const unsigned char *buf, int len)
 
char * osmo_osmo_hexdump_nospc (const unsigned char *buf, int len) __attribute__((__deprecated__))
 
void osmo_str2lower (char *out, const char *in)
 
void osmo_str2upper (char *out, const char *in)
 
int osmo_constant_time_cmp (const uint8_t *exp, const uint8_t *rel, const int count)
 
uint64_t osmo_decode_big_endian (const uint8_t *data, size_t data_len)
 
uint8_t * osmo_encode_big_endian (uint64_t value, size_t data_len)
 
size_t osmo_strlcpy (char *dst, const char *src, size_t siz)
 
bool osmo_is_hexstr (const char *str, int min_digits, int max_digits, bool require_even)
 
bool osmo_identifier_valid (const char *str)
 
bool osmo_separated_identifiers_valid (const char *str, const char *sep_chars)
 
const char * osmo_escape_str (const char *str, int len)
 
const char * osmo_escape_str_buf (const char *str, int in_len, char *buf, size_t bufsize)
 

Detailed Description

Macro Definition Documentation

◆ ARRAY_SIZE

#define ARRAY_SIZE (   x)    (sizeof(x) / sizeof((x)[0]))

Determine number of elements in an array of static size

◆ OSMO_ASSERT

#define OSMO_ASSERT (   exp)
Value:
if (!(exp)) { \
fprintf(stderr, "Assert failed %s %s:%d\n", #exp, __BASE_FILE__, __LINE__); \
/*osmo_generate_backtrace(); \ */\
abort(); \
}

Helper macro to terminate when an assertion failes

Parameters
[in]expPredicate to verify This function will generate a backtrace and terminate the program if the predicate evaluates to false (0).

◆ OSMO_BYTES_FOR_BITS

#define OSMO_BYTES_FOR_BITS (   BITS)    ((BITS + 8 - 1) / 8)

Number of bytes necessary to store given BITS

◆ OSMO_DEPRECATED

#define OSMO_DEPRECATED (   text)

Set the deprecated attribute with a message.

◆ OSMO_DEPRECATED_OUTSIDE_LIBOSMOCORE

#define OSMO_DEPRECATED_OUTSIDE_LIBOSMOCORE   OSMO_DEPRECATED("For internal use inside libosmocore only.")

◆ OSMO_GNUC_PREREQ

#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.

◆ OSMO_MAX

#define OSMO_MAX (   a,
 
)    ((a) >= (b) ? (a) : (b))

Return the maximum of two specified values

◆ OSMO_MIN

#define OSMO_MIN (   a,
 
)    ((a) >= (b) ? (b) : (a))

Return the minimum of two specified values

◆ OSMO_SNPRINTF_RET

#define OSMO_SNPRINTF_RET (   ret,
  rem,
  offset,
  len 
)
Value:
do { \
len += ret; \
if (ret > rem) \
ret = rem; \
offset += ret; \
rem -= ret; \
} while (0)

◆ osmo_static_assert

#define osmo_static_assert (   exp,
  name 
)    typedef int dummy##name [(exp) ? 1 : -1] __attribute__((__unused__));

◆ OSMO_STRINGIFY

#define OSMO_STRINGIFY (   x)    #x

Stringify the name of a macro x, e.g. an FSM event name. Note: if nested within another preprocessor macro, this will stringify the value of x instead of its name.

◆ OSMO_STRINGIFY_VAL

#define OSMO_STRINGIFY_VAL (   x)    OSMO_STRINGIFY(x)

Stringify the value of a macro x, e.g. a port number.

◆ OSMO_VALUE_STRING

#define OSMO_VALUE_STRING (   x)    { x, #x }

Make a value_string entry from an enum value name

Typedef Documentation

◆ osmo_panic_handler_t

typedef void(* osmo_panic_handler_t) (const char *fmt, va_list args)

panic handler callback function type

Function Documentation

◆ get_string_value()

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

◆ get_value_string_or_null()

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

◆ osmo_bcd2char()

char osmo_bcd2char ( uint8_t  bcd)

◆ osmo_char2bcd()

uint8_t osmo_char2bcd ( char  c)

◆ osmo_constant_time_cmp()

int osmo_constant_time_cmp ( const uint8_t *  exp,
const uint8_t *  rel,
const int  count 
)

duplicate a string using talloc and release its prior content (if any)

Parameters
[in]ctxTalloc context to use for allocation
[out]dstpointer to string, will be updated with ptr to new string
[in]newstrString that will be copieed to newly allocated string

Append to a string and re-/allocate if necessary.

Parameters
[in]ctxTalloc context to use for initial allocation.
[in,out]destchar* to re-/allocate and append to.
[in]fmtprintf-like string format.
[in]argsArguments for fmt.

dest may be passed in NULL, or a string previously allocated by talloc. If an existing string is passed in, it will remain associated with whichever ctx it was allocated before, regardless whether it matches ctx or not.

◆ osmo_decode_big_endian()

uint64_t osmo_decode_big_endian ( const uint8_t *  data,
size_t  data_len 
)

◆ osmo_encode_big_endian()

uint8_t* osmo_encode_big_endian ( uint64_t  value,
size_t  data_len 
)

◆ osmo_escape_str()

const char* osmo_escape_str ( const char *  str,
int  len 
)

◆ osmo_escape_str_buf()

const char* osmo_escape_str_buf ( const char *  str,
int  in_len,
char *  buf,
size_t  bufsize 
)

◆ osmo_hexdump()

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

◆ osmo_hexdump_nospc()

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

◆ osmo_identifier_valid()

bool osmo_identifier_valid ( const char *  str)

◆ osmo_is_hexstr()

bool osmo_is_hexstr ( const char *  str,
int  min_digits,
int  max_digits,
bool  require_even 
)

◆ osmo_osmo_hexdump_nospc()

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

◆ osmo_panic()

void osmo_panic ( const char *  fmt,
  ... 
)

◆ osmo_separated_identifiers_valid()

bool osmo_separated_identifiers_valid ( const char *  str,
const char *  sep_chars 
)

◆ osmo_set_panic_handler()

void osmo_set_panic_handler ( osmo_panic_handler_t  h)

◆ osmo_str2lower()

void osmo_str2lower ( char *  out,
const char *  in 
)

◆ osmo_str2upper()

void osmo_str2upper ( char *  out,
const char *  in 
)

◆ osmo_strlcpy()

size_t osmo_strlcpy ( char *  dst,
const char *  src,
size_t  siz 
)

◆ osmo_ubit_dump()

char* osmo_ubit_dump ( const uint8_t *  bits,
unsigned int  len 
)