\doxysection{General-\/purpose utility functions}
\label{group__utils}\index{General-\/purpose utility functions@{General-\/purpose utility functions}}


various utility routines  


\doxysubsection*{Files}
\begin{DoxyCompactItemize}
\item 
file \textbf{ defs.\+h}
\begin{DoxyCompactList}\small\item\em General definitions that are meant to be included from header files. \end{DoxyCompactList}\item 
file \textbf{ panic.\+h}
\item 
file \textbf{ utils.\+h}
\item 
file \textbf{ macaddr.\+c}
\begin{DoxyCompactList}\small\item\em MAC address utility routines. \end{DoxyCompactList}\item 
file \textbf{ panic.\+c}
\begin{DoxyCompactList}\small\item\em Routines for panic handling. \end{DoxyCompactList}\item 
file \textbf{ plugin.\+c}
\begin{DoxyCompactList}\small\item\em Routines for loading and managing shared library plug-\/ins. \end{DoxyCompactList}\item 
file \textbf{ strrb.\+c}
\begin{DoxyCompactList}\small\item\em Ringbuffer implementation, tailored for logging. \end{DoxyCompactList}\item 
file \textbf{ utils.\+c}
\end{DoxyCompactItemize}
\doxysubsection*{Data Structures}
\begin{DoxyCompactItemize}
\item 
struct \textbf{ value\+\_\+string}
\begin{DoxyCompactList}\small\item\em A mapping between human-\/readable string and numeric value. \end{DoxyCompactList}\item 
struct \textbf{ osmo\+\_\+strbuf}
\begin{DoxyCompactList}\small\item\em State for \doxyref{OSMO\+\_\+\+STRBUF\+\_\+\+APPEND()}{p.}{group__utils_gafff80b7c628a7b9138d0d663f6554de2} and \doxyref{OSMO\+\_\+\+STRBUF\+\_\+\+PRINTF()}{p.}{group__utils_ga5d295313b60e7dfe54cd0cd091733d49}. \end{DoxyCompactList}\end{DoxyCompactItemize}
\doxysubsection*{Macros}
\begin{DoxyCompactItemize}
\item 
\#define \textbf{ OSMO\+\_\+\+GNUC\+\_\+\+PREREQ}(maj,  min)~0
\begin{DoxyCompactList}\small\item\em Check for gcc and version. \end{DoxyCompactList}\item 
\#define \textbf{ OSMO\+\_\+\+DEPRECATED}(text)
\begin{DoxyCompactList}\small\item\em Set the deprecated attribute with a message. \end{DoxyCompactList}\item 
\#define \textbf{ OSMO\+\_\+\+DEPRECATED\+\_\+\+OUTSIDE\+\_\+\+LIBOSMOCORE}~\textbf{ OSMO\+\_\+\+DEPRECATED}(\char`\"{}For internal use inside \textbf{ libosmocore} only.\char`\"{})
\item 
\#define \textbf{ OSMO\+\_\+\+DEPRECATED\+\_\+\+OUTSIDE}(text)~\textbf{ OSMO\+\_\+\+DEPRECATED}(text)
\item 
\#define \textbf{ ARRAY\+\_\+\+SIZE}(\textbf{ x})~(sizeof(\textbf{ x}) / sizeof((\textbf{ x})[0]))
\begin{DoxyCompactList}\small\item\em Determine number of elements in an array of static size. \end{DoxyCompactList}\item 
\#define \textbf{ OSMO\+\_\+\+MAX}(a,  b)~((a) $>$= (b) ? (a) \+: (b))
\begin{DoxyCompactList}\small\item\em Return the maximum of two specified values. \end{DoxyCompactList}\item 
\#define \textbf{ OSMO\+\_\+\+MIN}(a,  b)~((a) $>$= (b) ? (b) \+: (a))
\begin{DoxyCompactList}\small\item\em Return the minimum of two specified values. \end{DoxyCompactList}\item 
\#define \textbf{ OSMO\+\_\+\+CMP}(a,  b)~((a) $<$ (b)? -\/1 \+: ((a) $>$ (b)? 1 \+: 0))
\begin{DoxyCompactList}\small\item\em Return a typical cmp result for comparable entities a and b. \end{DoxyCompactList}\item 
\#define \textbf{ OSMO\+\_\+\+STRINGIFY}(\textbf{ x})~\#\textbf{ x}
\begin{DoxyCompactList}\small\item\em Stringify the name of a macro x, e.\+g. \end{DoxyCompactList}\item 
\#define \textbf{ OSMO\+\_\+\+STRINGIFY\+\_\+\+VAL}(\textbf{ x})~\textbf{ OSMO\+\_\+\+STRINGIFY}(\textbf{ x})
\begin{DoxyCompactList}\small\item\em Stringify the value of a macro x, e.\+g. \end{DoxyCompactList}\item 
\#define \textbf{ OSMO\+\_\+\+VALUE\+\_\+\+STRING}(\textbf{ x})~\{ \textbf{ x}, \#\textbf{ x} \}
\begin{DoxyCompactList}\small\item\em Make a \doxyref{value\+\_\+string}{p.}{structvalue__string} entry from an enum value name. \end{DoxyCompactList}\item 
\#define \textbf{ OSMO\+\_\+\+BYTES\+\_\+\+FOR\+\_\+\+BITS}(BITS)~(((BITS) + 7) / 8)
\begin{DoxyCompactList}\small\item\em Number of bytes necessary to store given BITS. \end{DoxyCompactList}\item 
\#define \textbf{ OSMO\+\_\+\+STRLCPY\+\_\+\+ARRAY}(array,  src)~\textbf{ osmo\+\_\+strlcpy}(array, src, sizeof(array))
\begin{DoxyCompactList}\small\item\em Copy a C-\/string into a sized buffer using sizeof to detect buffer\textquotesingle{}s size. \end{DoxyCompactList}\item 
\#define \textbf{ OSMO\+\_\+\+LIKELY}(exp)~exp
\begin{DoxyCompactList}\small\item\em Branch prediction optimizations. \end{DoxyCompactList}\item 
\#define \textbf{ OSMO\+\_\+\+UNLIKELY}(exp)~exp
\item 
\#define \textbf{ osmo\+\_\+static\+\_\+assert}(exp,  \textbf{ name})~typedef int dummy\#\#\textbf{ name} [(exp) ? 1 \+: -\/1] \textbf{ \+\_\+\+\_\+attribute\+\_\+\+\_\+}((\+\_\+\+\_\+unused\+\_\+\+\_\+));
\item 
\#define \textbf{ OSMO\+\_\+\+SNPRINTF\+\_\+\+RET}(ret,  rem,  offset,  \textbf{ len})
\item 
\#define \textbf{ OSMO\+\_\+\+ASSERT}(exp)
\begin{DoxyCompactList}\small\item\em Helper macro to terminate when an assertion fails. \end{DoxyCompactList}\item 
\#define \textbf{ osmo\+\_\+talloc\+\_\+asprintf}(ctx,  dest,  fmt,  args ...)
\begin{DoxyCompactList}\small\item\em Append to a string and re-\//allocate if necessary. \end{DoxyCompactList}\item 
\#define \textbf{ OSMO\+\_\+\+MOD\+\_\+\+FLR}(\textbf{ x},  y)~(((\textbf{ x}) $>$ 0 \&\& (y) $<$ 0) $\vert$$\vert$ ((\textbf{ x}) $<$ 0 \&\& (y) $>$ 0) ? (\textbf{ x}) \% (y) + (y) \+: (\textbf{ x}) \% (y))
\begin{DoxyCompactList}\small\item\em Floored Modulo (See also\+: Daan Leijen, Division and Modulus for Computer Scientists). \end{DoxyCompactList}\item 
\#define \textbf{ OSMO\+\_\+\+MOD\+\_\+\+EUC}(\textbf{ x},  y)~((\textbf{ x}) \% (y) $<$ 0 ? (y) $>$ 0 ? (\textbf{ x}) \% (y) + (y) \+: (\textbf{ x}) \% (y) -\/ (y) \+: (\textbf{ x}) \% (y))
\begin{DoxyCompactList}\small\item\em Euclidean Modulo (See also\+: Daan Leijen, Division and Modulus for Computer Scientists). \end{DoxyCompactList}\item 
\#define \textbf{ OSMO\+\_\+\+STRBUF\+\_\+\+APPEND}(STRBUF,  func,  args...)
\begin{DoxyCompactList}\small\item\em Append a string to a buffer, as printed by an snprintf()-\/like function and with similar bounds checking. \end{DoxyCompactList}\item 
\#define \textbf{ OSMO\+\_\+\+STRBUF\+\_\+\+PRINTF}(STRBUF,  fmt,  args...)~ \textbf{ OSMO\+\_\+\+STRBUF\+\_\+\+APPEND}(STRBUF, snprintf, fmt, \#\#args)
\begin{DoxyCompactList}\small\item\em Shortcut for \doxyref{OSMO\+\_\+\+STRBUF\+\_\+\+APPEND()}{p.}{group__utils_gafff80b7c628a7b9138d0d663f6554de2} invocation using snprintf(). \end{DoxyCompactList}\item 
\#define \textbf{ OSMO\+\_\+\+STRBUF\+\_\+\+REMAIN}(STRBUF)~ \textbf{ \+\_\+osmo\+\_\+strbuf\+\_\+remain}(\&(STRBUF))
\begin{DoxyCompactList}\small\item\em Return remaining space for characters and terminating nul in the given struct \doxyref{osmo\+\_\+strbuf}{p.}{structosmo__strbuf}. \end{DoxyCompactList}\item 
\#define \textbf{ OSMO\+\_\+\+STRBUF\+\_\+\+CHAR\+\_\+\+COUNT}(STRBUF)~ \textbf{ \+\_\+osmo\+\_\+strbuf\+\_\+char\+\_\+count}(\&(STRBUF))
\begin{DoxyCompactList}\small\item\em Return number of actual characters contained in struct \doxyref{osmo\+\_\+strbuf}{p.}{structosmo__strbuf} (without terminating nul). \end{DoxyCompactList}\item 
\#define \textbf{ OSMO\+\_\+\+STRBUF\+\_\+\+APPEND\+\_\+\+NOLEN}(STRBUF,  func,  args...)
\begin{DoxyCompactList}\small\item\em Like \doxyref{OSMO\+\_\+\+STRBUF\+\_\+\+APPEND()}{p.}{group__utils_gafff80b7c628a7b9138d0d663f6554de2}, but for function signatures that return the char$\ast$ buffer instead of a length. \end{DoxyCompactList}\item 
\#define \textbf{ OSMO\+\_\+\+STRBUF\+\_\+\+DROP\+\_\+\+TAIL}(STRBUF,  N\+\_\+\+CHARS)~\textbf{ osmo\+\_\+strbuf\+\_\+drop\+\_\+tail}(\&(STRBUF), N\+\_\+\+CHARS)
\item 
\#define \textbf{ OSMO\+\_\+\+STRBUF\+\_\+\+ADDED\+\_\+\+TAIL}(STRBUF,  N\+\_\+\+CHARS)~\textbf{ osmo\+\_\+strbuf\+\_\+added\+\_\+tail}(\&(STRBUF), N\+\_\+\+CHARS)
\item 
\#define \textbf{ OSMO\+\_\+\+NAME\+\_\+\+C\+\_\+\+IMPL}(CTX,  INITIAL\+\_\+\+BUFSIZE,  ON\+\_\+\+ERROR,  FUNC\+\_\+\+BUF,  FUNC\+\_\+\+BUF\+\_\+\+ARGS...)
\begin{DoxyCompactList}\small\item\em Translate a buffer function to a talloc context function. \end{DoxyCompactList}\end{DoxyCompactItemize}
\doxysubsection*{Typedefs}
\begin{DoxyCompactItemize}
\item 
typedef void($\ast$ \textbf{ osmo\+\_\+panic\+\_\+handler\+\_\+t}) (const char $\ast$fmt, va\+\_\+list args)
\begin{DoxyCompactList}\small\item\em panic handler callback function type \end{DoxyCompactList}\end{DoxyCompactItemize}
\doxysubsection*{Functions}
\begin{DoxyCompactItemize}
\item 
void \textbf{ osmo\+\_\+panic} (const char $\ast$fmt,...)
\begin{DoxyCompactList}\small\item\em Terminate the current program with a panic. \end{DoxyCompactList}\item 
void \textbf{ osmo\+\_\+set\+\_\+panic\+\_\+handler} (\textbf{ osmo\+\_\+panic\+\_\+handler\+\_\+t} \textbf{ h})
\begin{DoxyCompactList}\small\item\em Set the panic handler. \end{DoxyCompactList}\item 
const char $\ast$ \textbf{ get\+\_\+value\+\_\+string} (const struct \textbf{ value\+\_\+string} $\ast$vs, uint32\+\_\+t val)
\begin{DoxyCompactList}\small\item\em get human-\/readable string for given value \end{DoxyCompactList}\item 
const char $\ast$ \textbf{ get\+\_\+value\+\_\+string\+\_\+or\+\_\+null} (const struct \textbf{ value\+\_\+string} $\ast$vs, uint32\+\_\+t val)
\begin{DoxyCompactList}\small\item\em get human-\/readable string or NULL for given value \end{DoxyCompactList}\item 
int \textbf{ get\+\_\+string\+\_\+value} (const struct \textbf{ value\+\_\+string} $\ast$vs, const char $\ast$str)
\begin{DoxyCompactList}\small\item\em get numeric value for given human-\/readable string \end{DoxyCompactList}\item 
char \textbf{ osmo\+\_\+bcd2char} (uint8\+\_\+t bcd)
\begin{DoxyCompactList}\small\item\em Convert BCD-\/encoded digit into printable character. \end{DoxyCompactList}\item 
uint8\+\_\+t \textbf{ osmo\+\_\+char2bcd} (char \textbf{ c})
\begin{DoxyCompactList}\small\item\em Convert number in ASCII to BCD value. \end{DoxyCompactList}\item 
int \textbf{ osmo\+\_\+bcd2str} (char $\ast$dst, size\+\_\+t dst\+\_\+size, const uint8\+\_\+t $\ast$bcd, int start\+\_\+nibble, int end\+\_\+nibble, bool allow\+\_\+hex)
\begin{DoxyCompactList}\small\item\em Convert BCD to string. \end{DoxyCompactList}\item 
int \textbf{ osmo\+\_\+str2bcd} (uint8\+\_\+t $\ast$dst, size\+\_\+t dst\+\_\+size, const char $\ast$\textbf{ digits}, int start\+\_\+nibble, int end\+\_\+nibble, bool allow\+\_\+hex)
\begin{DoxyCompactList}\small\item\em Convert string to BCD. \end{DoxyCompactList}\item 
int \textbf{ osmo\+\_\+hexparse} (const char $\ast$str, uint8\+\_\+t $\ast$b, unsigned int max\+\_\+len)
\begin{DoxyCompactList}\small\item\em Parse a string containing hexadecimal digits. \end{DoxyCompactList}\item 
char $\ast$ \textbf{ osmo\+\_\+ubit\+\_\+dump\+\_\+buf} (char $\ast$buf, size\+\_\+t buf\+\_\+len, const uint8\+\_\+t $\ast$bits, unsigned int \textbf{ len})
\begin{DoxyCompactList}\small\item\em Convert a sequence of unpacked bits to ASCII string, in user-\/supplied buffer. \end{DoxyCompactList}\item 
char $\ast$ \textbf{ osmo\+\_\+ubit\+\_\+dump} (const uint8\+\_\+t $\ast$bits, unsigned int \textbf{ len})
\begin{DoxyCompactList}\small\item\em Convert a sequence of unpacked bits to ASCII string, in static buffer. \end{DoxyCompactList}\item 
char $\ast$ \textbf{ osmo\+\_\+hexdump} (const unsigned char $\ast$buf, int \textbf{ len})
\begin{DoxyCompactList}\small\item\em Convert binary sequence to hexadecimal ASCII string. \end{DoxyCompactList}\item 
char $\ast$ \textbf{ osmo\+\_\+hexdump\+\_\+c} (const void $\ast$ctx, const unsigned char $\ast$buf, int \textbf{ len})
\begin{DoxyCompactList}\small\item\em Convert binary sequence to hexadecimal ASCII string. \end{DoxyCompactList}\item 
char $\ast$ \textbf{ osmo\+\_\+hexdump\+\_\+nospc} (const unsigned char $\ast$buf, int \textbf{ len})
\begin{DoxyCompactList}\small\item\em Convert binary sequence to hexadecimal ASCII string. \end{DoxyCompactList}\item 
char $\ast$ \textbf{ osmo\+\_\+hexdump\+\_\+nospc\+\_\+c} (const void $\ast$ctx, const unsigned char $\ast$buf, int \textbf{ len})
\begin{DoxyCompactList}\small\item\em Convert binary sequence to hexadecimal ASCII string. \end{DoxyCompactList}\item 
const char $\ast$ \textbf{ osmo\+\_\+hexdump\+\_\+buf} (char $\ast$out\+\_\+buf, size\+\_\+t out\+\_\+buf\+\_\+size, const unsigned char $\ast$buf, int \textbf{ len}, const char $\ast$delim, bool delim\+\_\+after\+\_\+last)
\begin{DoxyCompactList}\small\item\em Convert binary sequence to hexadecimal ASCII string. \end{DoxyCompactList}\item 
char $\ast$ \textbf{ osmo\+\_\+osmo\+\_\+hexdump\+\_\+nospc} (const unsigned char $\ast$buf, int \textbf{ len}) \textbf{ \+\_\+\+\_\+attribute\+\_\+\+\_\+}((\+\_\+\+\_\+deprecated\+\_\+\+\_\+))
\item 
void \textbf{ osmo\+\_\+str2lower} (char $\ast$out, const char $\ast$in) \textbf{ OSMO\+\_\+\+DEPRECATED}(\char`\"{}Use \textbf{ osmo\+\_\+str\+\_\+tolower}() or \textbf{ osmo\+\_\+str\+\_\+tolower\+\_\+buf}() \textbf{ instead}
\item 
void \textbf{ osmo\+\_\+str2upper} (char $\ast$out, const char $\ast$in) \textbf{ OSMO\+\_\+\+DEPRECATED}(\char`\"{}Use \textbf{ osmo\+\_\+str\+\_\+toupper}() or \textbf{ osmo\+\_\+str\+\_\+toupper\+\_\+buf}() \textbf{ instead}
\item 
size\+\_\+t \textbf{ osmo\+\_\+str\+\_\+tolower\+\_\+buf} (char $\ast$dest, size\+\_\+t dest\+\_\+len, const char $\ast$src)
\begin{DoxyCompactList}\small\item\em Convert a string to lowercase, while checking buffer size boundaries. \end{DoxyCompactList}\item 
const char $\ast$ \textbf{ osmo\+\_\+str\+\_\+tolower} (const char $\ast$src)
\begin{DoxyCompactList}\small\item\em Convert a string to lowercase, using a static buffer. \end{DoxyCompactList}\item 
char $\ast$ \textbf{ osmo\+\_\+str\+\_\+tolower\+\_\+c} (const void $\ast$ctx, const char $\ast$src)
\begin{DoxyCompactList}\small\item\em Convert a string to lowercase, dynamically allocating the output from given talloc context See also \doxyref{osmo\+\_\+str\+\_\+tolower\+\_\+buf()}{p.}{group__utils_ga8912910863d88f52b9d62220ee66feed}. \end{DoxyCompactList}\item 
size\+\_\+t \textbf{ osmo\+\_\+str\+\_\+toupper\+\_\+buf} (char $\ast$dest, size\+\_\+t dest\+\_\+len, const char $\ast$src)
\begin{DoxyCompactList}\small\item\em Convert a string to uppercase, while checking buffer size boundaries. \end{DoxyCompactList}\item 
const char $\ast$ \textbf{ osmo\+\_\+str\+\_\+toupper} (const char $\ast$src)
\begin{DoxyCompactList}\small\item\em Convert a string to uppercase, using a static buffer. \end{DoxyCompactList}\item 
char $\ast$ \textbf{ osmo\+\_\+str\+\_\+toupper\+\_\+c} (const void $\ast$ctx, const char $\ast$src)
\begin{DoxyCompactList}\small\item\em Convert a string to uppercase, dynamically allocating the output from given talloc context See also \doxyref{osmo\+\_\+str\+\_\+tolower\+\_\+buf()}{p.}{group__utils_ga8912910863d88f52b9d62220ee66feed}. \end{DoxyCompactList}\item 
static void \textbf{ osmo\+\_\+talloc\+\_\+replace\+\_\+string} (void $\ast$ctx, char $\ast$$\ast$dst, const char $\ast$newstr)
\begin{DoxyCompactList}\small\item\em duplicate a string using talloc and release its prior content (if any) \end{DoxyCompactList}\item 
void \textbf{ osmo\+\_\+talloc\+\_\+replace\+\_\+string\+\_\+fmt} (void $\ast$ctx, char $\ast$$\ast$dst, const char $\ast$fmt,...)
\begin{DoxyCompactList}\small\item\em Replace a string using talloc and release its prior content (if any). \end{DoxyCompactList}\item 
int \textbf{ osmo\+\_\+constant\+\_\+time\+\_\+cmp} (const uint8\+\_\+t $\ast$exp, const uint8\+\_\+t $\ast$rel, const int count)
\begin{DoxyCompactList}\small\item\em Wishful thinking to generate a constant time compare. \end{DoxyCompactList}\item 
uint64\+\_\+t \textbf{ osmo\+\_\+decode\+\_\+big\+\_\+endian} (const uint8\+\_\+t $\ast$\textbf{ data}, size\+\_\+t data\+\_\+len)
\begin{DoxyCompactList}\small\item\em Generic retrieval of 1..8 bytes as big-\/endian uint64\+\_\+t. \end{DoxyCompactList}\item 
uint8\+\_\+t $\ast$ \textbf{ osmo\+\_\+encode\+\_\+big\+\_\+endian} (uint64\+\_\+t value, size\+\_\+t data\+\_\+len)
\begin{DoxyCompactList}\small\item\em Generic big-\/endian encoding of big endian number up to 64bit. \end{DoxyCompactList}\item 
size\+\_\+t \textbf{ osmo\+\_\+strlcpy} (char $\ast$dst, const char $\ast$src, size\+\_\+t siz)
\begin{DoxyCompactList}\small\item\em Copy a C-\/string into a sized buffer. \end{DoxyCompactList}\item 
const char $\ast$ \textbf{ osmo\+\_\+strnchr} (const char $\ast$str, size\+\_\+t str\+\_\+size, char \textbf{ c})
\begin{DoxyCompactList}\small\item\em Find first occurence of a char in a size limited string. \end{DoxyCompactList}\item 
bool \textbf{ osmo\+\_\+is\+\_\+hexstr} (const char $\ast$str, int min\+\_\+digits, int max\+\_\+digits, bool require\+\_\+even)
\begin{DoxyCompactList}\small\item\em Validate that a given string is a hex string within given size limits. \end{DoxyCompactList}\item 
bool \textbf{ osmo\+\_\+identifier\+\_\+valid} (const char $\ast$str)
\begin{DoxyCompactList}\small\item\em Determine if a given identifier is valid, i.\+e. \end{DoxyCompactList}\item 
bool \textbf{ osmo\+\_\+separated\+\_\+identifiers\+\_\+valid} (const char $\ast$str, const char $\ast$sep\+\_\+chars)
\begin{DoxyCompactList}\small\item\em Determine if a given identifier is valid, i.\+e. \end{DoxyCompactList}\item 
void \textbf{ osmo\+\_\+identifier\+\_\+sanitize\+\_\+buf} (char $\ast$str, const char $\ast$sep\+\_\+chars, char replace\+\_\+with)
\begin{DoxyCompactList}\small\item\em Replace characters in the given string buffer so that it is guaranteed to pass \doxyref{osmo\+\_\+separated\+\_\+identifiers\+\_\+valid()}{p.}{group__utils_gabac697c1ef493cb5691eb5f11c4af984}. \end{DoxyCompactList}\item 
size\+\_\+t \textbf{ osmo\+\_\+escape\+\_\+cstr\+\_\+buf} (char $\ast$buf, size\+\_\+t bufsize, const char $\ast$str, int in\+\_\+len)
\begin{DoxyCompactList}\small\item\em Return the string with all non-\/printable characters escaped. \end{DoxyCompactList}\item 
char $\ast$ \textbf{ osmo\+\_\+escape\+\_\+cstr\+\_\+c} (void $\ast$ctx, const char $\ast$str, int in\+\_\+len)
\begin{DoxyCompactList}\small\item\em Return the string with all non-\/printable characters escaped, in dynamically-\/allocated buffer. \end{DoxyCompactList}\item 
size\+\_\+t \textbf{ osmo\+\_\+quote\+\_\+cstr\+\_\+buf} (char $\ast$buf, size\+\_\+t bufsize, const char $\ast$str, int in\+\_\+len)
\begin{DoxyCompactList}\small\item\em Like \doxyref{osmo\+\_\+escape\+\_\+str\+\_\+buf2()}{p.}{group__utils_gab6d6c37d5cc2807eb63b41498f38fb9d}, but returns double-\/quotes around a string, or \char`\"{}\+NULL\char`\"{} for a NULL string. \end{DoxyCompactList}\item 
char $\ast$ \textbf{ osmo\+\_\+quote\+\_\+cstr\+\_\+c} (void $\ast$ctx, const char $\ast$str, int in\+\_\+len)
\begin{DoxyCompactList}\small\item\em Return the string quoted and with all non-\/printable characters escaped, in dynamically-\/allocated buffer. \end{DoxyCompactList}\item 
const char $\ast$ \textbf{ osmo\+\_\+escape\+\_\+str} (const char $\ast$str, int in\+\_\+len)
\begin{DoxyCompactList}\small\item\em Return the string with all non-\/printable characters escaped. \end{DoxyCompactList}\item 
int \textbf{ osmo\+\_\+escape\+\_\+str\+\_\+buf3} (char $\ast$buf, size\+\_\+t bufsize, const char $\ast$str, int in\+\_\+len)
\begin{DoxyCompactList}\small\item\em Return the string with all non-\/printable characters escaped. \end{DoxyCompactList}\item 
char $\ast$ \textbf{ osmo\+\_\+escape\+\_\+str\+\_\+buf2} (char $\ast$buf, size\+\_\+t bufsize, const char $\ast$str, int in\+\_\+len)
\begin{DoxyCompactList}\small\item\em Return the string with all non-\/printable characters escaped. \end{DoxyCompactList}\item 
const char $\ast$ \textbf{ osmo\+\_\+escape\+\_\+str\+\_\+buf} (const char $\ast$str, int in\+\_\+len, char $\ast$buf, size\+\_\+t bufsize)
\begin{DoxyCompactList}\small\item\em Like osmo\+\_\+escape\+\_\+str\+\_\+buf2, but with unusual ordering of arguments, and may sometimes return string constants instead of writing to buf for error cases or empty input. \end{DoxyCompactList}\item 
char $\ast$ \textbf{ osmo\+\_\+escape\+\_\+str\+\_\+c} (const void $\ast$ctx, const char $\ast$str, int in\+\_\+len)
\begin{DoxyCompactList}\small\item\em Return the string with all non-\/printable characters escaped, in dynamically-\/allocated buffer. \end{DoxyCompactList}\item 
const char $\ast$ \textbf{ osmo\+\_\+quote\+\_\+str} (const char $\ast$str, int in\+\_\+len)
\begin{DoxyCompactList}\small\item\em Like \doxyref{osmo\+\_\+quote\+\_\+str\+\_\+buf()}{p.}{group__utils_gad5c8e9dbe2d66556fde2a49418d2db89} but returns the result in a static buffer. \end{DoxyCompactList}\item 
int \textbf{ osmo\+\_\+quote\+\_\+str\+\_\+buf3} (char $\ast$buf, size\+\_\+t bufsize, const char $\ast$str, int in\+\_\+len)
\begin{DoxyCompactList}\small\item\em Like \doxyref{osmo\+\_\+escape\+\_\+str\+\_\+buf3()}{p.}{group__utils_ga6b4866958eb385b561fc1fa91db242e7}, but returns double-\/quotes around a string, or \char`\"{}\+NULL\char`\"{} for a NULL string. \end{DoxyCompactList}\item 
char $\ast$ \textbf{ osmo\+\_\+quote\+\_\+str\+\_\+buf2} (char $\ast$buf, size\+\_\+t bufsize, const char $\ast$str, int in\+\_\+len)
\begin{DoxyCompactList}\small\item\em Like \doxyref{osmo\+\_\+escape\+\_\+str\+\_\+buf2()}{p.}{group__utils_gab6d6c37d5cc2807eb63b41498f38fb9d}, but returns double-\/quotes around a string, or \char`\"{}\+NULL\char`\"{} for a NULL string. \end{DoxyCompactList}\item 
const char $\ast$ \textbf{ osmo\+\_\+quote\+\_\+str\+\_\+buf} (const char $\ast$str, int in\+\_\+len, char $\ast$buf, size\+\_\+t bufsize)
\begin{DoxyCompactList}\small\item\em Like osmo\+\_\+quote\+\_\+str\+\_\+buf2, but with unusual ordering of arguments, and may sometimes return string constants instead of writing to buf for error cases or empty input. \end{DoxyCompactList}\item 
char $\ast$ \textbf{ osmo\+\_\+quote\+\_\+str\+\_\+c} (const void $\ast$ctx, const char $\ast$str, int in\+\_\+len)
\begin{DoxyCompactList}\small\item\em Like \doxyref{osmo\+\_\+quote\+\_\+str\+\_\+buf()}{p.}{group__utils_gad5c8e9dbe2d66556fde2a49418d2db89} but returns the result in a dynamically-\/allocated buffer. \end{DoxyCompactList}\item 
int \textbf{ osmo\+\_\+print\+\_\+n} (char $\ast$buf, size\+\_\+t bufsize, const char $\ast$str, size\+\_\+t \textbf{ n})
\begin{DoxyCompactList}\small\item\em Copy N characters to a buffer with a function signature useful for \doxyref{OSMO\+\_\+\+STRBUF\+\_\+\+APPEND()}{p.}{group__utils_gafff80b7c628a7b9138d0d663f6554de2}. \end{DoxyCompactList}\item 
uint32\+\_\+t \textbf{ osmo\+\_\+isqrt32} (uint32\+\_\+t \textbf{ x})
\begin{DoxyCompactList}\small\item\em perform an integer square root operation on unsigned 32bit integer. \end{DoxyCompactList}\item 
char \textbf{ osmo\+\_\+luhn} (const char $\ast$in, int in\+\_\+len)
\begin{DoxyCompactList}\small\item\em Calculate the Luhn checksum (as used for IMEIs). \end{DoxyCompactList}\item 
static size\+\_\+t \textbf{ \+\_\+osmo\+\_\+strbuf\+\_\+remain} (const struct \textbf{ osmo\+\_\+strbuf} $\ast$sb)
\begin{DoxyCompactList}\small\item\em Get remaining space for characters and terminating nul in the given struct \doxyref{osmo\+\_\+strbuf}{p.}{structosmo__strbuf}. \end{DoxyCompactList}\item 
static size\+\_\+t \textbf{ \+\_\+osmo\+\_\+strbuf\+\_\+char\+\_\+count} (const struct \textbf{ osmo\+\_\+strbuf} $\ast$sb)
\begin{DoxyCompactList}\small\item\em Get number of actual characters (without terminating nul) in the given struct \doxyref{osmo\+\_\+strbuf}{p.}{structosmo__strbuf}. \end{DoxyCompactList}\item 
void \textbf{ osmo\+\_\+strbuf\+\_\+drop\+\_\+tail} (struct \textbf{ osmo\+\_\+strbuf} $\ast$sb, size\+\_\+t n\+\_\+chars)
\begin{DoxyCompactList}\small\item\em Remove up to N chars from the end of an \doxyref{osmo\+\_\+strbuf}{p.}{structosmo__strbuf}. \end{DoxyCompactList}\item 
void \textbf{ osmo\+\_\+strbuf\+\_\+added\+\_\+tail} (struct \textbf{ osmo\+\_\+strbuf} $\ast$sb, size\+\_\+t n\+\_\+chars)
\begin{DoxyCompactList}\small\item\em Let \doxyref{osmo\+\_\+strbuf}{p.}{structosmo__strbuf} know that n\+\_\+chars characters (excluding nul) were written to the end of the buffer. \end{DoxyCompactList}\item 
bool \textbf{ osmo\+\_\+str\+\_\+startswith} (const char $\ast$str, const char $\ast$startswith\+\_\+str)
\begin{DoxyCompactList}\small\item\em Compare start of a string. \end{DoxyCompactList}\item 
int \textbf{ osmo\+\_\+float\+\_\+str\+\_\+to\+\_\+int} (int64\+\_\+t $\ast$val, const char $\ast$str, unsigned int precision)
\begin{DoxyCompactList}\small\item\em Convert a string of a floating point number to a signed int, with a decimal factor (fixed-\/point precision). \end{DoxyCompactList}\item 
int \textbf{ osmo\+\_\+int\+\_\+to\+\_\+float\+\_\+str\+\_\+buf} (char $\ast$buf, size\+\_\+t buflen, int64\+\_\+t val, unsigned int precision)
\begin{DoxyCompactList}\small\item\em Convert an integer to a floating point string using a decimal quotient (fixed-\/point precision). \end{DoxyCompactList}\item 
char $\ast$ \textbf{ osmo\+\_\+int\+\_\+to\+\_\+float\+\_\+str\+\_\+c} (void $\ast$ctx, int64\+\_\+t val, unsigned int precision)
\begin{DoxyCompactList}\small\item\em Convert an integer with a factor of a million to a floating point string. \end{DoxyCompactList}\item 
int \textbf{ osmo\+\_\+str\+\_\+to\+\_\+int64} (int64\+\_\+t $\ast$result, const char $\ast$str, int base, int64\+\_\+t min\+\_\+val, int64\+\_\+t max\+\_\+val)
\begin{DoxyCompactList}\small\item\em Convert a string of a number to int64\+\_\+t, including all common strtoll() validity checks. \end{DoxyCompactList}\item 
int \textbf{ osmo\+\_\+str\+\_\+to\+\_\+int} (int $\ast$result, const char $\ast$str, int base, int min\+\_\+val, int max\+\_\+val)
\begin{DoxyCompactList}\small\item\em Convert a string of a number to int, including all common strtoll() validity checks. \end{DoxyCompactList}\item 
int \textbf{ osmo\+\_\+macaddr\+\_\+parse} (uint8\+\_\+t $\ast$out, const char $\ast$in)
\begin{DoxyCompactList}\small\item\em Parse a MAC address from human-\/readable notation This function parses an ethernet MAC address in the commonly-\/used hex/colon notation (00\+:00\+:00\+:00\+:00\+:00) and generates the binary representation from it. \end{DoxyCompactList}\item 
int \textbf{ osmo\+\_\+get\+\_\+macaddr} (uint8\+\_\+t $\ast$mac\+\_\+out, const char $\ast$dev\+\_\+name)
\begin{DoxyCompactList}\small\item\em Obtain the MAC address of a given network device. \end{DoxyCompactList}\item 
static void \textbf{ osmo\+\_\+panic\+\_\+default} (const char $\ast$fmt, va\+\_\+list args)
\item 
int \textbf{ osmo\+\_\+plugin\+\_\+load\+\_\+all} (const char $\ast$directory)
\item 
struct \textbf{ osmo\+\_\+strrb} $\ast$ \textbf{ osmo\+\_\+strrb\+\_\+create} (void $\ast$talloc\+\_\+ctx, size\+\_\+t rb\+\_\+size)
\begin{DoxyCompactList}\small\item\em Create an empty, initialized \doxyref{osmo\+\_\+strrb}{p.}{structosmo__strrb}. \end{DoxyCompactList}\item 
bool \textbf{ osmo\+\_\+strrb\+\_\+is\+\_\+empty} (const struct \textbf{ osmo\+\_\+strrb} $\ast$rb)
\begin{DoxyCompactList}\small\item\em Check if an \doxyref{osmo\+\_\+strrb}{p.}{structosmo__strrb} is empty. \end{DoxyCompactList}\item 
const char $\ast$ \textbf{ osmo\+\_\+strrb\+\_\+get\+\_\+nth} (const struct \textbf{ osmo\+\_\+strrb} $\ast$rb, unsigned int string\+\_\+index)
\begin{DoxyCompactList}\small\item\em Return a pointer to the Nth string in the \doxyref{osmo\+\_\+strrb}{p.}{structosmo__strrb}. \end{DoxyCompactList}\item 
bool \textbf{ \+\_\+osmo\+\_\+strrb\+\_\+is\+\_\+bufindex\+\_\+valid} (const struct \textbf{ osmo\+\_\+strrb} $\ast$rb, unsigned int bufi)
\item 
size\+\_\+t \textbf{ osmo\+\_\+strrb\+\_\+elements} (const struct \textbf{ osmo\+\_\+strrb} $\ast$rb)
\begin{DoxyCompactList}\small\item\em Count the number of log messages in an \doxyref{osmo\+\_\+strrb}{p.}{structosmo__strrb}. \end{DoxyCompactList}\item 
int \textbf{ osmo\+\_\+strrb\+\_\+add} (struct \textbf{ osmo\+\_\+strrb} $\ast$rb, const char $\ast$\textbf{ data})
\begin{DoxyCompactList}\small\item\em Add a string to the \doxyref{osmo\+\_\+strrb}{p.}{structosmo__strrb}. \end{DoxyCompactList}\item 
char \textbf{ alias} (\char`\"{}osmo\+\_\+hexdump\+\_\+nospc\char`\"{})))
\item 
static int \textbf{ \+\_\+osmo\+\_\+escape\+\_\+str\+\_\+buf} (char $\ast$buf, size\+\_\+t bufsize, const char $\ast$str, int in\+\_\+len, bool legacy\+\_\+format)
\begin{DoxyCompactList}\small\item\em Return the string with all non-\/printable characters escaped. \end{DoxyCompactList}\item 
static size\+\_\+t \textbf{ \+\_\+osmo\+\_\+quote\+\_\+str\+\_\+buf} (char $\ast$buf, size\+\_\+t bufsize, const char $\ast$str, int in\+\_\+len, bool legacy\+\_\+format)
\begin{DoxyCompactList}\small\item\em Return a quoted and escaped representation of the string. \end{DoxyCompactList}\end{DoxyCompactItemize}
\doxysubsection*{Variables}
\begin{DoxyCompactItemize}
\item 
void to properly check target \textbf{ memory} \textbf{ bounds}
\item 
static \textbf{ osmo\+\_\+panic\+\_\+handler\+\_\+t} \textbf{ osmo\+\_\+panic\+\_\+handler} = (void$\ast$)0
\item 
static \+\_\+\+\_\+thread char \textbf{ namebuf} [255]
\item 
static \+\_\+\+\_\+thread char \textbf{ capsbuf} [128]
\item 
static \+\_\+\+\_\+thread char \textbf{ hexd\+\_\+buff} [4096]
\item 
static const char \textbf{ hex\+\_\+chars} [$\,$] = \char`\"{}0123456789abcdef\char`\"{}
\item 
static const char \textbf{ osmo\+\_\+identifier\+\_\+illegal\+\_\+chars} [$\,$] = \char`\"{}., \{\}[$\,$]()$<$$>$$\vert$$\sim$\textbackslash{}\textbackslash{}$^\wedge$\`{}\textquotesingle{}\textbackslash{}\char`\"{}?=;/+$\ast$\&\%\$\#!\char`\"{}
\end{DoxyCompactItemize}


\doxysubsection{Detailed Description}
various utility routines 



\doxysubsection{Macro Definition Documentation}
\mbox{\label{group__utils_ga6242a25f9d996f0cc4f4cdb911218b75}} 
\index{General-\/purpose utility functions@{General-\/purpose utility functions}!ARRAY\_SIZE@{ARRAY\_SIZE}}
\index{ARRAY\_SIZE@{ARRAY\_SIZE}!General-\/purpose utility functions@{General-\/purpose utility functions}}
\doxysubsubsection{ARRAY\_SIZE}
{\footnotesize\ttfamily \#define ARRAY\+\_\+\+SIZE(\begin{DoxyParamCaption}\item[{}]{\textbf{ x} }\end{DoxyParamCaption})~(sizeof(\textbf{ x}) / sizeof((\textbf{ x})[0]))}



Determine number of elements in an array of static size. 

\mbox{\label{group__utils_ga0e15c1ca106fdf15e53b6b8cb30e87dd}} 
\index{General-\/purpose utility functions@{General-\/purpose utility functions}!OSMO\_ASSERT@{OSMO\_ASSERT}}
\index{OSMO\_ASSERT@{OSMO\_ASSERT}!General-\/purpose utility functions@{General-\/purpose utility functions}}
\doxysubsubsection{OSMO\_ASSERT}
{\footnotesize\ttfamily \#define OSMO\+\_\+\+ASSERT(\begin{DoxyParamCaption}\item[{}]{exp }\end{DoxyParamCaption})}

{\bfseries Value\+:}
\begin{DoxyCode}{0}
\DoxyCodeLine{\textcolor{keywordflow}{do} \{ \(\backslash\)}
\DoxyCodeLine{        if (OSMO\_UNLIKELY(!(exp))) \{ \(\backslash\)}
\DoxyCodeLine{                osmo\_panic(\textcolor{stringliteral}{"{}Assert failed \%s \%s:\%d\(\backslash\)n"{}}, \#exp, \_\_FILE\_\_, \_\_LINE\_\_); \(\backslash\)}
\DoxyCodeLine{        \} \(\backslash\)}
\DoxyCodeLine{\} \textcolor{keywordflow}{while} (0); \textcolor{comment}{/* some code invokes OSMO\_ASSERT() without the semicolon */}}

\end{DoxyCode}


Helper macro to terminate when an assertion fails. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em exp} & Predicate to verify This function will generate a backtrace and terminate the program if the predicate evaluates to false (0). \\
\hline
\end{DoxyParams}
\mbox{\label{group__utils_ga067f0d8cff5425054650f5562d25e6a4}} 
\index{General-\/purpose utility functions@{General-\/purpose utility functions}!OSMO\_BYTES\_FOR\_BITS@{OSMO\_BYTES\_FOR\_BITS}}
\index{OSMO\_BYTES\_FOR\_BITS@{OSMO\_BYTES\_FOR\_BITS}!General-\/purpose utility functions@{General-\/purpose utility functions}}
\doxysubsubsection{OSMO\_BYTES\_FOR\_BITS}
{\footnotesize\ttfamily \#define OSMO\+\_\+\+BYTES\+\_\+\+FOR\+\_\+\+BITS(\begin{DoxyParamCaption}\item[{}]{BITS }\end{DoxyParamCaption})~(((BITS) + 7) / 8)}



Number of bytes necessary to store given BITS. 

\mbox{\label{group__utils_ga85b341fffd41bb9900b0ede1f24295f0}} 
\index{General-\/purpose utility functions@{General-\/purpose utility functions}!OSMO\_CMP@{OSMO\_CMP}}
\index{OSMO\_CMP@{OSMO\_CMP}!General-\/purpose utility functions@{General-\/purpose utility functions}}
\doxysubsubsection{OSMO\_CMP}
{\footnotesize\ttfamily \#define OSMO\+\_\+\+CMP(\begin{DoxyParamCaption}\item[{}]{a,  }\item[{}]{b }\end{DoxyParamCaption})~((a) $<$ (b)? -\/1 \+: ((a) $>$ (b)? 1 \+: 0))}



Return a typical cmp result for comparable entities a and b. 

\mbox{\label{group__utils_gaae50be441dbfc7f95c61fdde4cdfb111}} 
\index{General-\/purpose utility functions@{General-\/purpose utility functions}!OSMO\_DEPRECATED@{OSMO\_DEPRECATED}}
\index{OSMO\_DEPRECATED@{OSMO\_DEPRECATED}!General-\/purpose utility functions@{General-\/purpose utility functions}}
\doxysubsubsection{OSMO\_DEPRECATED}
{\footnotesize\ttfamily \#define OSMO\+\_\+\+DEPRECATED(\begin{DoxyParamCaption}\item[{}]{text }\end{DoxyParamCaption})}



Set the deprecated attribute with a message. 

\mbox{\label{group__utils_ga18c73792dc759e9a929f5feda0d22f6e}} 
\index{General-\/purpose utility functions@{General-\/purpose utility functions}!OSMO\_DEPRECATED\_OUTSIDE@{OSMO\_DEPRECATED\_OUTSIDE}}
\index{OSMO\_DEPRECATED\_OUTSIDE@{OSMO\_DEPRECATED\_OUTSIDE}!General-\/purpose utility functions@{General-\/purpose utility functions}}
\doxysubsubsection{OSMO\_DEPRECATED\_OUTSIDE}
{\footnotesize\ttfamily \#define OSMO\+\_\+\+DEPRECATED\+\_\+\+OUTSIDE(\begin{DoxyParamCaption}\item[{}]{text }\end{DoxyParamCaption})~\textbf{ OSMO\+\_\+\+DEPRECATED}(text)}

\mbox{\label{group__utils_ga9fc6cb4f6eae2ccd7fb2ec67a38b6fb8}} 
\index{General-\/purpose utility functions@{General-\/purpose utility functions}!OSMO\_DEPRECATED\_OUTSIDE\_LIBOSMOCORE@{OSMO\_DEPRECATED\_OUTSIDE\_LIBOSMOCORE}}
\index{OSMO\_DEPRECATED\_OUTSIDE\_LIBOSMOCORE@{OSMO\_DEPRECATED\_OUTSIDE\_LIBOSMOCORE}!General-\/purpose utility functions@{General-\/purpose utility functions}}
\doxysubsubsection{OSMO\_DEPRECATED\_OUTSIDE\_LIBOSMOCORE}
{\footnotesize\ttfamily \#define OSMO\+\_\+\+DEPRECATED\+\_\+\+OUTSIDE\+\_\+\+LIBOSMOCORE~\textbf{ OSMO\+\_\+\+DEPRECATED}(\char`\"{}For internal use inside \textbf{ libosmocore} only.\char`\"{})}

\mbox{\label{group__utils_ga74e01f67651f36d2eb902d318fb3f1b5}} 
\index{General-\/purpose utility functions@{General-\/purpose utility functions}!OSMO\_GNUC\_PREREQ@{OSMO\_GNUC\_PREREQ}}
\index{OSMO\_GNUC\_PREREQ@{OSMO\_GNUC\_PREREQ}!General-\/purpose utility functions@{General-\/purpose utility functions}}
\doxysubsubsection{OSMO\_GNUC\_PREREQ}
{\footnotesize\ttfamily \#define OSMO\+\_\+\+GNUC\+\_\+\+PREREQ(\begin{DoxyParamCaption}\item[{}]{maj,  }\item[{}]{min }\end{DoxyParamCaption})~0}



Check for gcc and version. 

\begin{DoxyNote}{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.
\end{DoxyNote}
\begin{DoxyReturn}{Returns}
!= 0 iff gcc is used and it\textquotesingle{}s version is at least maj.\+min. 
\end{DoxyReturn}
\mbox{\label{group__utils_ga86f03e8039d84cdb5cd191561bb20815}} 
\index{General-\/purpose utility functions@{General-\/purpose utility functions}!OSMO\_LIKELY@{OSMO\_LIKELY}}
\index{OSMO\_LIKELY@{OSMO\_LIKELY}!General-\/purpose utility functions@{General-\/purpose utility functions}}
\doxysubsubsection{OSMO\_LIKELY}
{\footnotesize\ttfamily \#define OSMO\+\_\+\+LIKELY(\begin{DoxyParamCaption}\item[{}]{exp }\end{DoxyParamCaption})~exp}



Branch prediction optimizations. 

\mbox{\label{group__utils_gae29f3c348613687ee200b5632cf25baa}} 
\index{General-\/purpose utility functions@{General-\/purpose utility functions}!OSMO\_MAX@{OSMO\_MAX}}
\index{OSMO\_MAX@{OSMO\_MAX}!General-\/purpose utility functions@{General-\/purpose utility functions}}
\doxysubsubsection{OSMO\_MAX}
{\footnotesize\ttfamily \#define OSMO\+\_\+\+MAX(\begin{DoxyParamCaption}\item[{}]{a,  }\item[{}]{b }\end{DoxyParamCaption})~((a) $>$= (b) ? (a) \+: (b))}



Return the maximum of two specified values. 

\mbox{\label{group__utils_ga1f5ad4e4f1d11d303c80570dfe535b43}} 
\index{General-\/purpose utility functions@{General-\/purpose utility functions}!OSMO\_MIN@{OSMO\_MIN}}
\index{OSMO\_MIN@{OSMO\_MIN}!General-\/purpose utility functions@{General-\/purpose utility functions}}
\doxysubsubsection{OSMO\_MIN}
{\footnotesize\ttfamily \#define OSMO\+\_\+\+MIN(\begin{DoxyParamCaption}\item[{}]{a,  }\item[{}]{b }\end{DoxyParamCaption})~((a) $>$= (b) ? (b) \+: (a))}



Return the minimum of two specified values. 

\mbox{\label{group__utils_ga5590f4ac10e4986cd36ac9cc23021c8f}} 
\index{General-\/purpose utility functions@{General-\/purpose utility functions}!OSMO\_MOD\_EUC@{OSMO\_MOD\_EUC}}
\index{OSMO\_MOD\_EUC@{OSMO\_MOD\_EUC}!General-\/purpose utility functions@{General-\/purpose utility functions}}
\doxysubsubsection{OSMO\_MOD\_EUC}
{\footnotesize\ttfamily \#define OSMO\+\_\+\+MOD\+\_\+\+EUC(\begin{DoxyParamCaption}\item[{}]{\textbf{ x},  }\item[{}]{y }\end{DoxyParamCaption})~((\textbf{ x}) \% (y) $<$ 0 ? (y) $>$ 0 ? (\textbf{ x}) \% (y) + (y) \+: (\textbf{ x}) \% (y) -\/ (y) \+: (\textbf{ x}) \% (y))}



Euclidean Modulo (See also\+: Daan Leijen, Division and Modulus for Computer Scientists). 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em x} & dividend. \\
\hline
\mbox{\texttt{ in}}  & {\em y} & divisor. \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
remainder of x divided by y. 
\end{DoxyReturn}
\mbox{\label{group__utils_gaba46e9a38032320a7cc816056d94177f}} 
\index{General-\/purpose utility functions@{General-\/purpose utility functions}!OSMO\_MOD\_FLR@{OSMO\_MOD\_FLR}}
\index{OSMO\_MOD\_FLR@{OSMO\_MOD\_FLR}!General-\/purpose utility functions@{General-\/purpose utility functions}}
\doxysubsubsection{OSMO\_MOD\_FLR}
{\footnotesize\ttfamily \#define OSMO\+\_\+\+MOD\+\_\+\+FLR(\begin{DoxyParamCaption}\item[{}]{\textbf{ x},  }\item[{}]{y }\end{DoxyParamCaption})~(((\textbf{ x}) $>$ 0 \&\& (y) $<$ 0) $\vert$$\vert$ ((\textbf{ x}) $<$ 0 \&\& (y) $>$ 0) ? (\textbf{ x}) \% (y) + (y) \+: (\textbf{ x}) \% (y))}



Floored Modulo (See also\+: Daan Leijen, Division and Modulus for Computer Scientists). 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em x} & dividend. \\
\hline
\mbox{\texttt{ in}}  & {\em y} & divisor. \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
remainder of x divided by y. 
\end{DoxyReturn}
\mbox{\label{group__utils_gaae8fb831ea7b48b5d54f3a5a5f0a30bf}} 
\index{General-\/purpose utility functions@{General-\/purpose utility functions}!OSMO\_NAME\_C\_IMPL@{OSMO\_NAME\_C\_IMPL}}
\index{OSMO\_NAME\_C\_IMPL@{OSMO\_NAME\_C\_IMPL}!General-\/purpose utility functions@{General-\/purpose utility functions}}
\doxysubsubsection{OSMO\_NAME\_C\_IMPL}
{\footnotesize\ttfamily \#define OSMO\+\_\+\+NAME\+\_\+\+C\+\_\+\+IMPL(\begin{DoxyParamCaption}\item[{}]{CTX,  }\item[{}]{INITIAL\+\_\+\+BUFSIZE,  }\item[{}]{ON\+\_\+\+ERROR,  }\item[{}]{FUNC\+\_\+\+BUF,  }\item[{}]{FUNC\+\_\+\+BUF\+\_\+\+ARGS... }\end{DoxyParamCaption})}



Translate a buffer function to a talloc context function. 

This is the full function body of a char $\ast$foo\+\_\+name\+\_\+c(void $\ast$ctx, val...) function, implemented by an int foo\+\_\+name\+\_\+buf(buf, buflen, val...) function\+:

char $\ast$foo\+\_\+name\+\_\+c(void $\ast$ctx, example\+\_\+t arg) \{ OSMO\+\_\+\+NAME\+\_\+\+C\+\_\+\+IMPL(ctx, 64, \char`\"{}\+ERROR\char`\"{}, foo\+\_\+name\+\_\+buf, arg) \}

Return a talloc\textquotesingle{}d string containing the result of the given foo\+\_\+name\+\_\+buf() function, or ON\+\_\+\+ERROR on error in the called foo\+\_\+name\+\_\+buf() function.

If ON\+\_\+\+ERROR is NULL, the function returns NULL on error rc from FUNC\+\_\+\+BUF. Take care\+: returning NULL in printf() like formats (\doxyref{LOGP()}{p.}{group__logging_ga7e3a9f703edc9b95a8548a656a6f686d}) makes the program crash. If ON\+\_\+\+ERROR is non-\/\+NULL, it must be a string constant, which is not returned directly, but written to an allocated string buffer first.


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em INITIAL\+\_\+\+BUFSIZE} & Which size to first talloc from ctx -- a larger size makes a reallocation less likely, a smaller size allocates less unused bytes, zero allocates once but still runs the string composition twice. \\
\hline
\mbox{\texttt{ in}}  & {\em ON\+\_\+\+ERROR} & String constant to copy on error rc returned by FUNC\+\_\+\+BUF, or NULL to return NULL. \\
\hline
\mbox{\texttt{ in}}  & {\em FUNC\+\_\+\+BUF} & Name of a function with signature int foo\+\_\+buf(char $\ast$buf, size\+\_\+t buflen, ...). The function must return the strlen() that it would write to a sufficiently large buffer or negative on error, like snprintf(). \\
\hline
\mbox{\texttt{ in}}  & {\em FUNC\+\_\+\+BUF\+\_\+\+ARGS} & Additional arguments to pass to FUNC\+\_\+\+BUF after the buf and buflen. \\
\hline
\end{DoxyParams}
\mbox{\label{group__utils_gae2fd89d51ccb1101e04eb2d2c6d57cb0}} 
\index{General-\/purpose utility functions@{General-\/purpose utility functions}!OSMO\_SNPRINTF\_RET@{OSMO\_SNPRINTF\_RET}}
\index{OSMO\_SNPRINTF\_RET@{OSMO\_SNPRINTF\_RET}!General-\/purpose utility functions@{General-\/purpose utility functions}}
\doxysubsubsection{OSMO\_SNPRINTF\_RET}
{\footnotesize\ttfamily \#define OSMO\+\_\+\+SNPRINTF\+\_\+\+RET(\begin{DoxyParamCaption}\item[{}]{ret,  }\item[{}]{rem,  }\item[{}]{offset,  }\item[{}]{\textbf{ len} }\end{DoxyParamCaption})}

{\bfseries Value\+:}
\begin{DoxyCode}{0}
\DoxyCodeLine{\textcolor{keywordflow}{do} \{                                                            \(\backslash\)}
\DoxyCodeLine{        len += ret;                                             \(\backslash\)}
\DoxyCodeLine{        if (ret > rem)                                          \(\backslash\)}
\DoxyCodeLine{                ret = rem;                                      \(\backslash\)}
\DoxyCodeLine{        offset += ret;                                          \(\backslash\)}
\DoxyCodeLine{        rem -\/= ret;                                             \(\backslash\)}
\DoxyCodeLine{\} \textcolor{keywordflow}{while} (0)}

\end{DoxyCode}
\mbox{\label{group__utils_gaa235735a8fc8c2dc05243d6c8d355cc9}} 
\index{General-\/purpose utility functions@{General-\/purpose utility functions}!osmo\_static\_assert@{osmo\_static\_assert}}
\index{osmo\_static\_assert@{osmo\_static\_assert}!General-\/purpose utility functions@{General-\/purpose utility functions}}
\doxysubsubsection{osmo\_static\_assert}
{\footnotesize\ttfamily \#define osmo\+\_\+static\+\_\+assert(\begin{DoxyParamCaption}\item[{}]{exp,  }\item[{}]{\textbf{ name} }\end{DoxyParamCaption})~typedef int dummy\#\#\textbf{ name} [(exp) ? 1 \+: -\/1] \textbf{ \+\_\+\+\_\+attribute\+\_\+\+\_\+}((\+\_\+\+\_\+unused\+\_\+\+\_\+));}

\mbox{\label{group__utils_ga5e4bfb6fa08dec1257c3e6b4e6d442dd}} 
\index{General-\/purpose utility functions@{General-\/purpose utility functions}!OSMO\_STRBUF\_ADDED\_TAIL@{OSMO\_STRBUF\_ADDED\_TAIL}}
\index{OSMO\_STRBUF\_ADDED\_TAIL@{OSMO\_STRBUF\_ADDED\_TAIL}!General-\/purpose utility functions@{General-\/purpose utility functions}}
\doxysubsubsection{OSMO\_STRBUF\_ADDED\_TAIL}
{\footnotesize\ttfamily \#define OSMO\+\_\+\+STRBUF\+\_\+\+ADDED\+\_\+\+TAIL(\begin{DoxyParamCaption}\item[{}]{STRBUF,  }\item[{}]{N\+\_\+\+CHARS }\end{DoxyParamCaption})~\textbf{ osmo\+\_\+strbuf\+\_\+added\+\_\+tail}(\&(STRBUF), N\+\_\+\+CHARS)}

\mbox{\label{group__utils_gafff80b7c628a7b9138d0d663f6554de2}} 
\index{General-\/purpose utility functions@{General-\/purpose utility functions}!OSMO\_STRBUF\_APPEND@{OSMO\_STRBUF\_APPEND}}
\index{OSMO\_STRBUF\_APPEND@{OSMO\_STRBUF\_APPEND}!General-\/purpose utility functions@{General-\/purpose utility functions}}
\doxysubsubsection{OSMO\_STRBUF\_APPEND}
{\footnotesize\ttfamily \#define OSMO\+\_\+\+STRBUF\+\_\+\+APPEND(\begin{DoxyParamCaption}\item[{}]{STRBUF,  }\item[{}]{func,  }\item[{}]{args... }\end{DoxyParamCaption})}

{\bfseries Value\+:}
\begin{DoxyCode}{0}
\DoxyCodeLine{                \textcolor{keywordflow}{do} \{ \(\backslash\)}
\DoxyCodeLine{                if (!(STRBUF).pos) \(\backslash\)}
\DoxyCodeLine{                        (STRBUF).pos = (STRBUF).buf; \(\backslash\)}
\DoxyCodeLine{                size\_t \_sb\_remain = OSMO\_STRBUF\_REMAIN(STRBUF); \(\backslash\)}
\DoxyCodeLine{                int \_sb\_l = func((STRBUF).pos, \_sb\_remain, \#\#args); \(\backslash\)}
\DoxyCodeLine{                if (\_sb\_l < 0 || (\textcolor{keywordtype}{size\_t})\_sb\_l > \_sb\_remain) \(\backslash\)}
\DoxyCodeLine{                        (STRBUF).pos = (STRBUF).buf + (STRBUF).len; \(\backslash\)}
\DoxyCodeLine{                else \textcolor{keywordflow}{if} ((STRBUF).pos) \(\backslash\)}
\DoxyCodeLine{                        (STRBUF).pos += \_sb\_l; \(\backslash\)}
\DoxyCodeLine{                if (\_sb\_l > 0) \(\backslash\)}
\DoxyCodeLine{                        (STRBUF).chars\_needed += \_sb\_l; \(\backslash\)}
\DoxyCodeLine{        \} \textcolor{keywordflow}{while}(0)}

\end{DoxyCode}


Append a string to a buffer, as printed by an snprintf()-\/like function and with similar bounds checking. 

Make sure to never write past the end of the buffer, and collect the total size that would be needed. \begin{DoxyVerb}// an example function implementation to append: write N spaces.
int print_spaces(char *dst, size_t dst_len, int n)
{
        int i;
        if (n < 0)
                return -EINVAL;
        for (i = 0; i < n && i < dst_len; i++)
                dst[i] = ' ';
        if (dst_len)
                dst[OSMO_MIN(dst_len - 1, n)] = '\0';
        // return the n that we would have liked to write if space were available:
        return n;
}

// append above spaces as well as an snprintf()
void strbuf_example()
{
        char buf[23];
        struct osmo_strbuf sb = { .buf = buf, .len = sizeof(buf) };

        OSMO_STRBUF_APPEND(sb, print_spaces, 5);
        OSMO_STRBUF_APPEND(sb, snprintf, "The answer is %d but what is the question?", 42);
        OSMO_STRBUF_APPEND(sb, print_spaces, 423423);

        printf("%s\n", buf);
        printf("would have needed %zu bytes\n", sb.chars_needed);
}
\end{DoxyVerb}
 
\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in,out}}  & {\em STRBUF} & A struct \doxyref{osmo\+\_\+strbuf}{p.}{structosmo__strbuf} instance. \\
\hline
\mbox{\texttt{ in}}  & {\em func} & A function with a signature of int func(char $\ast$dst, size\+\_\+t dst\+\_\+len [, args]) with semantics like snprintf(). \\
\hline
\mbox{\texttt{ in}}  & {\em args} & Arguments passed to func, if any. \\
\hline
\end{DoxyParams}
\mbox{\label{group__utils_gaba053478cf0abc6d10ada0851e796a4b}} 
\index{General-\/purpose utility functions@{General-\/purpose utility functions}!OSMO\_STRBUF\_APPEND\_NOLEN@{OSMO\_STRBUF\_APPEND\_NOLEN}}
\index{OSMO\_STRBUF\_APPEND\_NOLEN@{OSMO\_STRBUF\_APPEND\_NOLEN}!General-\/purpose utility functions@{General-\/purpose utility functions}}
\doxysubsubsection{OSMO\_STRBUF\_APPEND\_NOLEN}
{\footnotesize\ttfamily \#define OSMO\+\_\+\+STRBUF\+\_\+\+APPEND\+\_\+\+NOLEN(\begin{DoxyParamCaption}\item[{}]{STRBUF,  }\item[{}]{func,  }\item[{}]{args... }\end{DoxyParamCaption})}

{\bfseries Value\+:}
\begin{DoxyCode}{0}
\DoxyCodeLine{                \textcolor{keywordflow}{do} \{ \(\backslash\)}
\DoxyCodeLine{                if (!(STRBUF).pos) \(\backslash\)}
\DoxyCodeLine{                        (STRBUF).pos = (STRBUF).buf; \(\backslash\)}
\DoxyCodeLine{                size\_t \_sb\_remain = OSMO\_STRBUF\_REMAIN(STRBUF); \(\backslash\)}
\DoxyCodeLine{                if (\_sb\_remain) \{ \(\backslash\)}
\DoxyCodeLine{                        func((STRBUF).pos, \_sb\_remain, \#\#args); \(\backslash\)}
\DoxyCodeLine{                \} \(\backslash\)}
\DoxyCodeLine{                size\_t \_sb\_l = (STRBUF).pos ? strnlen((STRBUF).pos, \_sb\_remain) : 0; \(\backslash\)}
\DoxyCodeLine{                if (\_sb\_l > \_sb\_remain) \(\backslash\)}
\DoxyCodeLine{                        (STRBUF).pos = (STRBUF).buf + (STRBUF).len; \(\backslash\)}
\DoxyCodeLine{                else \textcolor{keywordflow}{if} ((STRBUF).pos) \(\backslash\)}
\DoxyCodeLine{                        (STRBUF).pos += \_sb\_l; \(\backslash\)}
\DoxyCodeLine{                (STRBUF).chars\_needed += \_sb\_l; \(\backslash\)}
\DoxyCodeLine{        \} \textcolor{keywordflow}{while}(0)}

\end{DoxyCode}


Like \doxyref{OSMO\+\_\+\+STRBUF\+\_\+\+APPEND()}{p.}{group__utils_gafff80b7c628a7b9138d0d663f6554de2}, but for function signatures that return the char$\ast$ buffer instead of a length. 

When using this function, the final STRBUF.\+chars\+\_\+needed may not reflect the actual number of characters needed, since that number cannot be obtained from this kind of function signature. 
\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in,out}}  & {\em STRBUF} & A struct \doxyref{osmo\+\_\+strbuf}{p.}{structosmo__strbuf} instance. \\
\hline
\mbox{\texttt{ in}}  & {\em func} & A function with a signature of char $\ast$func(char $\ast$dst, size\+\_\+t dst\+\_\+len [, args]) where the returned string is always written to dst. \\
\hline
\mbox{\texttt{ in}}  & {\em args} & Arguments passed to func, if any. \\
\hline
\end{DoxyParams}
\mbox{\label{group__utils_ga35daf5bea23a8e172e32f8e321b191c2}} 
\index{General-\/purpose utility functions@{General-\/purpose utility functions}!OSMO\_STRBUF\_CHAR\_COUNT@{OSMO\_STRBUF\_CHAR\_COUNT}}
\index{OSMO\_STRBUF\_CHAR\_COUNT@{OSMO\_STRBUF\_CHAR\_COUNT}!General-\/purpose utility functions@{General-\/purpose utility functions}}
\doxysubsubsection{OSMO\_STRBUF\_CHAR\_COUNT}
{\footnotesize\ttfamily \#define OSMO\+\_\+\+STRBUF\+\_\+\+CHAR\+\_\+\+COUNT(\begin{DoxyParamCaption}\item[{}]{STRBUF }\end{DoxyParamCaption})~ \textbf{ \+\_\+osmo\+\_\+strbuf\+\_\+char\+\_\+count}(\&(STRBUF))}



Return number of actual characters contained in struct \doxyref{osmo\+\_\+strbuf}{p.}{structosmo__strbuf} (without terminating nul). 

\mbox{\label{group__utils_ga8aca577fe1c05f829a5399d141e4aa2c}} 
\index{General-\/purpose utility functions@{General-\/purpose utility functions}!OSMO\_STRBUF\_DROP\_TAIL@{OSMO\_STRBUF\_DROP\_TAIL}}
\index{OSMO\_STRBUF\_DROP\_TAIL@{OSMO\_STRBUF\_DROP\_TAIL}!General-\/purpose utility functions@{General-\/purpose utility functions}}
\doxysubsubsection{OSMO\_STRBUF\_DROP\_TAIL}
{\footnotesize\ttfamily \#define OSMO\+\_\+\+STRBUF\+\_\+\+DROP\+\_\+\+TAIL(\begin{DoxyParamCaption}\item[{}]{STRBUF,  }\item[{}]{N\+\_\+\+CHARS }\end{DoxyParamCaption})~\textbf{ osmo\+\_\+strbuf\+\_\+drop\+\_\+tail}(\&(STRBUF), N\+\_\+\+CHARS)}

\mbox{\label{group__utils_ga5d295313b60e7dfe54cd0cd091733d49}} 
\index{General-\/purpose utility functions@{General-\/purpose utility functions}!OSMO\_STRBUF\_PRINTF@{OSMO\_STRBUF\_PRINTF}}
\index{OSMO\_STRBUF\_PRINTF@{OSMO\_STRBUF\_PRINTF}!General-\/purpose utility functions@{General-\/purpose utility functions}}
\doxysubsubsection{OSMO\_STRBUF\_PRINTF}
{\footnotesize\ttfamily \#define OSMO\+\_\+\+STRBUF\+\_\+\+PRINTF(\begin{DoxyParamCaption}\item[{}]{STRBUF,  }\item[{}]{fmt,  }\item[{}]{args... }\end{DoxyParamCaption})~ \textbf{ OSMO\+\_\+\+STRBUF\+\_\+\+APPEND}(STRBUF, snprintf, fmt, \#\#args)}



Shortcut for \doxyref{OSMO\+\_\+\+STRBUF\+\_\+\+APPEND()}{p.}{group__utils_gafff80b7c628a7b9138d0d663f6554de2} invocation using snprintf(). 

int strbuf\+\_\+example2(char $\ast$buf, size\+\_\+t buflen) \{ int i; struct \doxyref{osmo\+\_\+strbuf}{p.}{structosmo__strbuf} sb = \{ .buf = buf, .len = buflen \};

OSMO\+\_\+\+STRBUF\+\_\+\+PRINTF(sb, \char`\"{}\+T minus\char`\"{}); for (i = 10; i; i--) OSMO\+\_\+\+STRBUF\+\_\+\+PRINTF(sb, \char`\"{} \%d\char`\"{}, i); OSMO\+\_\+\+STRBUF\+\_\+\+PRINTF(sb, \char`\"{} ... Lift off!\char`\"{});

return sb.\+chars\+\_\+needed; \}


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in,out}}  & {\em STRBUF} & A struct \doxyref{osmo\+\_\+strbuf}{p.}{structosmo__strbuf} instance. \\
\hline
\mbox{\texttt{ in}}  & {\em fmt} & Format string passed to snprintf. \\
\hline
\mbox{\texttt{ in}}  & {\em args} & Additional arguments passed to snprintf, if any. \\
\hline
\end{DoxyParams}
\mbox{\label{group__utils_gac498e594ee1e828ecac2f13907a73bc6}} 
\index{General-\/purpose utility functions@{General-\/purpose utility functions}!OSMO\_STRBUF\_REMAIN@{OSMO\_STRBUF\_REMAIN}}
\index{OSMO\_STRBUF\_REMAIN@{OSMO\_STRBUF\_REMAIN}!General-\/purpose utility functions@{General-\/purpose utility functions}}
\doxysubsubsection{OSMO\_STRBUF\_REMAIN}
{\footnotesize\ttfamily \#define OSMO\+\_\+\+STRBUF\+\_\+\+REMAIN(\begin{DoxyParamCaption}\item[{}]{STRBUF }\end{DoxyParamCaption})~ \textbf{ \+\_\+osmo\+\_\+strbuf\+\_\+remain}(\&(STRBUF))}



Return remaining space for characters and terminating nul in the given struct \doxyref{osmo\+\_\+strbuf}{p.}{structosmo__strbuf}. 

\mbox{\label{group__utils_ga99c393c0cc777531381ef27b9e63fa01}} 
\index{General-\/purpose utility functions@{General-\/purpose utility functions}!OSMO\_STRINGIFY@{OSMO\_STRINGIFY}}
\index{OSMO\_STRINGIFY@{OSMO\_STRINGIFY}!General-\/purpose utility functions@{General-\/purpose utility functions}}
\doxysubsubsection{OSMO\_STRINGIFY}
{\footnotesize\ttfamily \#define OSMO\+\_\+\+STRINGIFY(\begin{DoxyParamCaption}\item[{}]{\textbf{ x} }\end{DoxyParamCaption})~\#\textbf{ 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. \mbox{\label{group__utils_ga9273786c95d1934af2aa371d63c7611a}} 
\index{General-\/purpose utility functions@{General-\/purpose utility functions}!OSMO\_STRINGIFY\_VAL@{OSMO\_STRINGIFY\_VAL}}
\index{OSMO\_STRINGIFY\_VAL@{OSMO\_STRINGIFY\_VAL}!General-\/purpose utility functions@{General-\/purpose utility functions}}
\doxysubsubsection{OSMO\_STRINGIFY\_VAL}
{\footnotesize\ttfamily \#define OSMO\+\_\+\+STRINGIFY\+\_\+\+VAL(\begin{DoxyParamCaption}\item[{}]{\textbf{ x} }\end{DoxyParamCaption})~\textbf{ OSMO\+\_\+\+STRINGIFY}(\textbf{ x})}



Stringify the value of a macro x, e.\+g. 

a port number. \mbox{\label{group__utils_ga355219208ac32aa4ce67361306c45f33}} 
\index{General-\/purpose utility functions@{General-\/purpose utility functions}!OSMO\_STRLCPY\_ARRAY@{OSMO\_STRLCPY\_ARRAY}}
\index{OSMO\_STRLCPY\_ARRAY@{OSMO\_STRLCPY\_ARRAY}!General-\/purpose utility functions@{General-\/purpose utility functions}}
\doxysubsubsection{OSMO\_STRLCPY\_ARRAY}
{\footnotesize\ttfamily \#define OSMO\+\_\+\+STRLCPY\+\_\+\+ARRAY(\begin{DoxyParamCaption}\item[{}]{array,  }\item[{}]{src }\end{DoxyParamCaption})~\textbf{ osmo\+\_\+strlcpy}(array, src, sizeof(array))}



Copy a C-\/string into a sized buffer using sizeof to detect buffer\textquotesingle{}s size. 

\mbox{\label{group__utils_gab694a7bcd176825e1b7fd43fdd13eeaa}} 
\index{General-\/purpose utility functions@{General-\/purpose utility functions}!osmo\_talloc\_asprintf@{osmo\_talloc\_asprintf}}
\index{osmo\_talloc\_asprintf@{osmo\_talloc\_asprintf}!General-\/purpose utility functions@{General-\/purpose utility functions}}
\doxysubsubsection{osmo\_talloc\_asprintf}
{\footnotesize\ttfamily \#define osmo\+\_\+talloc\+\_\+asprintf(\begin{DoxyParamCaption}\item[{}]{ctx,  }\item[{}]{dest,  }\item[{}]{fmt,  }\item[{}]{args ... }\end{DoxyParamCaption})}

{\bfseries Value\+:}
\begin{DoxyCode}{0}
\DoxyCodeLine{        \textcolor{keywordflow}{do} \{ \(\backslash\)}
\DoxyCodeLine{                if (!dest) \(\backslash\)}
\DoxyCodeLine{                        dest = talloc\_asprintf(ctx, fmt, \#\# args); \(\backslash\)}
\DoxyCodeLine{                else \(\backslash\)}
\DoxyCodeLine{                        dest = talloc\_asprintf\_append((\textcolor{keywordtype}{char}*)dest, fmt, \#\# args); \(\backslash\)}
\DoxyCodeLine{        \} \textcolor{keywordflow}{while} (0)}

\end{DoxyCode}


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


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em ctx} & Talloc context to use for initial allocation. \\
\hline
\mbox{\texttt{ in,out}}  & {\em dest} & char$\ast$ to re-\//allocate and append to. \\
\hline
\mbox{\texttt{ in}}  & {\em fmt} & printf-\/like string format. \\
\hline
\mbox{\texttt{ in}}  & {\em args} & Arguments for fmt.\\
\hline
\end{DoxyParams}
{\itshape 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 {\itshape ctx} or not. \mbox{\label{group__utils_ga02420271059f041f43be5593c8378226}} 
\index{General-\/purpose utility functions@{General-\/purpose utility functions}!OSMO\_UNLIKELY@{OSMO\_UNLIKELY}}
\index{OSMO\_UNLIKELY@{OSMO\_UNLIKELY}!General-\/purpose utility functions@{General-\/purpose utility functions}}
\doxysubsubsection{OSMO\_UNLIKELY}
{\footnotesize\ttfamily \#define OSMO\+\_\+\+UNLIKELY(\begin{DoxyParamCaption}\item[{}]{exp }\end{DoxyParamCaption})~exp}

\mbox{\label{group__utils_gaec58324388fc88645f98b409bfedf1b3}} 
\index{General-\/purpose utility functions@{General-\/purpose utility functions}!OSMO\_VALUE\_STRING@{OSMO\_VALUE\_STRING}}
\index{OSMO\_VALUE\_STRING@{OSMO\_VALUE\_STRING}!General-\/purpose utility functions@{General-\/purpose utility functions}}
\doxysubsubsection{OSMO\_VALUE\_STRING}
{\footnotesize\ttfamily \#define OSMO\+\_\+\+VALUE\+\_\+\+STRING(\begin{DoxyParamCaption}\item[{}]{\textbf{ x} }\end{DoxyParamCaption})~\{ \textbf{ x}, \#\textbf{ x} \}}



Make a \doxyref{value\+\_\+string}{p.}{structvalue__string} entry from an enum value name. 



\doxysubsection{Typedef Documentation}
\mbox{\label{group__utils_ga23bc29d21400af02d00e4741d96b8e73}} 
\index{General-\/purpose utility functions@{General-\/purpose utility functions}!osmo\_panic\_handler\_t@{osmo\_panic\_handler\_t}}
\index{osmo\_panic\_handler\_t@{osmo\_panic\_handler\_t}!General-\/purpose utility functions@{General-\/purpose utility functions}}
\doxysubsubsection{osmo\_panic\_handler\_t}
{\footnotesize\ttfamily typedef void($\ast$ osmo\+\_\+panic\+\_\+handler\+\_\+t) (const char $\ast$fmt, va\+\_\+list args)}



panic handler callback function type 



\doxysubsection{Function Documentation}
\mbox{\label{group__utils_gaa273befac18c6df037af4e01e8fd1cd7}} 
\index{General-\/purpose utility functions@{General-\/purpose utility functions}!\_osmo\_escape\_str\_buf@{\_osmo\_escape\_str\_buf}}
\index{\_osmo\_escape\_str\_buf@{\_osmo\_escape\_str\_buf}!General-\/purpose utility functions@{General-\/purpose utility functions}}
\doxysubsubsection{\_osmo\_escape\_str\_buf()}
{\footnotesize\ttfamily static int \+\_\+osmo\+\_\+escape\+\_\+str\+\_\+buf (\begin{DoxyParamCaption}\item[{char $\ast$}]{buf,  }\item[{size\+\_\+t}]{bufsize,  }\item[{const char $\ast$}]{str,  }\item[{int}]{in\+\_\+len,  }\item[{bool}]{legacy\+\_\+format }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [static]}}



Return the string with all non-\/printable characters escaped. 

This internal function is the implementation for all osmo\+\_\+escape\+\_\+str$\ast$ and osmo\+\_\+quote\+\_\+str$\ast$ API versions. It provides both the legacy (non C compatible) escaping, as well as C compatible string constant syntax, and it provides a return value of characters-\/needed, to allow producing un-\/truncated strings in all cases. 
\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ out}}  & {\em buf} & string buffer to write escaped characters to. \\
\hline
\mbox{\texttt{ in}}  & {\em bufsize} & sizeof(buf). \\
\hline
\mbox{\texttt{ in}}  & {\em str} & A string that may contain any characters. \\
\hline
\mbox{\texttt{ in}}  & {\em in\+\_\+len} & Pass -\/1 to print until nul char, or $>$= 0 to force a length (also past nul chars). \\
\hline
\mbox{\texttt{ in}}  & {\em legacy\+\_\+format} & If false, return C compatible string constants (\char`\"{}\textbackslash{}x0f\char`\"{}), if true the legacy escaping format (\char`\"{}\textbackslash{}15\char`\"{}). The legacy format also escapes as \char`\"{}\textbackslash{}a\textbackslash{}b\textbackslash{}f\textbackslash{}v\char`\"{}, while the non-\/legacy format also escapes those as \char`\"{}\textbackslash{}x\+NN\char`\"{} sequences. \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
Number of characters that would be written if bufsize were large enough excluding \textquotesingle{}\textbackslash{}0\textquotesingle{} (like snprintf()). 
\end{DoxyReturn}


References \textbf{ BACKSLASH\+\_\+\+CASE}, \textbf{ osmo\+\_\+strbuf\+::buf}, \textbf{ osmo\+\_\+strbuf\+::chars\+\_\+needed}, \textbf{ osmo\+\_\+print\+\_\+n()}, \textbf{ OSMO\+\_\+\+STRBUF\+\_\+\+APPEND}, and \textbf{ OSMO\+\_\+\+STRBUF\+\_\+\+PRINTF}.



Referenced by \textbf{ \+\_\+osmo\+\_\+quote\+\_\+str\+\_\+buf()}, \textbf{ osmo\+\_\+escape\+\_\+cstr\+\_\+buf()}, \textbf{ osmo\+\_\+escape\+\_\+cstr\+\_\+c()}, \textbf{ osmo\+\_\+escape\+\_\+str\+\_\+buf2()}, \textbf{ osmo\+\_\+escape\+\_\+str\+\_\+buf3()}, and \textbf{ osmo\+\_\+escape\+\_\+str\+\_\+c()}.

\mbox{\label{group__utils_gaede6980e9fac6f132c8b7a80fa0311bb}} 
\index{General-\/purpose utility functions@{General-\/purpose utility functions}!\_osmo\_quote\_str\_buf@{\_osmo\_quote\_str\_buf}}
\index{\_osmo\_quote\_str\_buf@{\_osmo\_quote\_str\_buf}!General-\/purpose utility functions@{General-\/purpose utility functions}}
\doxysubsubsection{\_osmo\_quote\_str\_buf()}
{\footnotesize\ttfamily static size\+\_\+t \+\_\+osmo\+\_\+quote\+\_\+str\+\_\+buf (\begin{DoxyParamCaption}\item[{char $\ast$}]{buf,  }\item[{size\+\_\+t}]{bufsize,  }\item[{const char $\ast$}]{str,  }\item[{int}]{in\+\_\+len,  }\item[{bool}]{legacy\+\_\+format }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [static]}}



Return a quoted and escaped representation of the string. 

This internal function is the implementation for all osmo\+\_\+quote\+\_\+str$\ast$ API versions. It provides both the legacy (non C compatible) escaping, as well as C compatible string constant syntax, and it provides a return value of characters-\/needed, to allow producing un-\/truncated strings in all cases. 
\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ out}}  & {\em buf} & string buffer to write escaped characters to. \\
\hline
\mbox{\texttt{ in}}  & {\em bufsize} & sizeof(buf). \\
\hline
\mbox{\texttt{ in}}  & {\em str} & A string that may contain any characters. \\
\hline
\mbox{\texttt{ in}}  & {\em in\+\_\+len} & Pass -\/1 to print until nul char, or $>$= 0 to force a length (also past nul chars). \\
\hline
\mbox{\texttt{ in}}  & {\em legacy\+\_\+format} & If false, return C compatible string constants (\char`\"{}\textbackslash{}x0f\char`\"{}), if true the legacy escaping format (\char`\"{}\textbackslash{}15\char`\"{}). The legacy format also escapes as \char`\"{}\textbackslash{}a\textbackslash{}b\textbackslash{}f\textbackslash{}v\char`\"{}, while the non-\/legacy format also escapes those as \char`\"{}\textbackslash{}x\+NN\char`\"{} sequences. \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
Number of characters that would be written if bufsize were large enough excluding \textquotesingle{}\textbackslash{}0\textquotesingle{} (like snprintf()). 
\end{DoxyReturn}


References \textbf{ \+\_\+osmo\+\_\+escape\+\_\+str\+\_\+buf()}, \textbf{ osmo\+\_\+strbuf\+::buf}, \textbf{ osmo\+\_\+strbuf\+::chars\+\_\+needed}, \textbf{ OSMO\+\_\+\+STRBUF\+\_\+\+APPEND}, and \textbf{ OSMO\+\_\+\+STRBUF\+\_\+\+PRINTF}.



Referenced by \textbf{ osmo\+\_\+quote\+\_\+cstr\+\_\+buf()}, \textbf{ osmo\+\_\+quote\+\_\+cstr\+\_\+c()}, \textbf{ osmo\+\_\+quote\+\_\+str()}, \textbf{ osmo\+\_\+quote\+\_\+str\+\_\+buf()}, \textbf{ osmo\+\_\+quote\+\_\+str\+\_\+buf2()}, \textbf{ osmo\+\_\+quote\+\_\+str\+\_\+buf3()}, and \textbf{ osmo\+\_\+quote\+\_\+str\+\_\+c()}.

\mbox{\label{group__utils_ga4216b0fe4cfd873c359bcf34a4dd7fc6}} 
\index{General-\/purpose utility functions@{General-\/purpose utility functions}!\_osmo\_strbuf\_char\_count@{\_osmo\_strbuf\_char\_count}}
\index{\_osmo\_strbuf\_char\_count@{\_osmo\_strbuf\_char\_count}!General-\/purpose utility functions@{General-\/purpose utility functions}}
\doxysubsubsection{\_osmo\_strbuf\_char\_count()}
{\footnotesize\ttfamily static size\+\_\+t \+\_\+osmo\+\_\+strbuf\+\_\+char\+\_\+count (\begin{DoxyParamCaption}\item[{const struct \textbf{ osmo\+\_\+strbuf} $\ast$}]{sb }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [inline]}, {\ttfamily [static]}}



Get number of actual characters (without terminating nul) in the given struct \doxyref{osmo\+\_\+strbuf}{p.}{structosmo__strbuf}. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em sb} & the string buffer to get the number of characters for. \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
number of actual characters (without terminating nul). 
\end{DoxyReturn}


References \textbf{ osmo\+\_\+strbuf\+::buf}, \textbf{ osmo\+\_\+strbuf\+::len}, \textbf{ OSMO\+\_\+\+MIN}, \textbf{ OSMO\+\_\+\+UNLIKELY}, and \textbf{ osmo\+\_\+strbuf\+::pos}.

\mbox{\label{group__utils_ga2505d8e3b82c608039ef6df2897ec561}} 
\index{General-\/purpose utility functions@{General-\/purpose utility functions}!\_osmo\_strbuf\_remain@{\_osmo\_strbuf\_remain}}
\index{\_osmo\_strbuf\_remain@{\_osmo\_strbuf\_remain}!General-\/purpose utility functions@{General-\/purpose utility functions}}
\doxysubsubsection{\_osmo\_strbuf\_remain()}
{\footnotesize\ttfamily static size\+\_\+t \+\_\+osmo\+\_\+strbuf\+\_\+remain (\begin{DoxyParamCaption}\item[{const struct \textbf{ osmo\+\_\+strbuf} $\ast$}]{sb }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [inline]}, {\ttfamily [static]}}



Get remaining space for characters and terminating nul in the given struct \doxyref{osmo\+\_\+strbuf}{p.}{structosmo__strbuf}. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em sb} & the string buffer to get the remaining space for. \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
remaining space in the given struct \doxyref{osmo\+\_\+strbuf}{p.}{structosmo__strbuf}. 
\end{DoxyReturn}


References \textbf{ osmo\+\_\+strbuf\+::buf}, \textbf{ osmo\+\_\+strbuf\+::len}, \textbf{ OSMO\+\_\+\+UNLIKELY}, and \textbf{ osmo\+\_\+strbuf\+::pos}.

\mbox{\label{group__utils_gab46115cd7bc48f5b20b7281bf64ef1e2}} 
\index{General-\/purpose utility functions@{General-\/purpose utility functions}!\_osmo\_strrb\_is\_bufindex\_valid@{\_osmo\_strrb\_is\_bufindex\_valid}}
\index{\_osmo\_strrb\_is\_bufindex\_valid@{\_osmo\_strrb\_is\_bufindex\_valid}!General-\/purpose utility functions@{General-\/purpose utility functions}}
\doxysubsubsection{\_osmo\_strrb\_is\_bufindex\_valid()}
{\footnotesize\ttfamily bool \+\_\+osmo\+\_\+strrb\+\_\+is\+\_\+bufindex\+\_\+valid (\begin{DoxyParamCaption}\item[{const struct \textbf{ osmo\+\_\+strrb} $\ast$}]{rb,  }\item[{unsigned int}]{bufi }\end{DoxyParamCaption})}



References \textbf{ osmo\+\_\+strrb\+::end}, \textbf{ osmo\+\_\+strrb\+\_\+is\+\_\+empty()}, \textbf{ osmo\+\_\+strrb\+::size}, and \textbf{ osmo\+\_\+strrb\+::start}.



Referenced by \textbf{ osmo\+\_\+strrb\+\_\+get\+\_\+nth()}.

\mbox{\label{group__utils_gadc9804584fe701ac5eebf9f091f45314}} 
\index{General-\/purpose utility functions@{General-\/purpose utility functions}!alias@{alias}}
\index{alias@{alias}!General-\/purpose utility functions@{General-\/purpose utility functions}}
\doxysubsubsection{alias()}
{\footnotesize\ttfamily char alias (\begin{DoxyParamCaption}\item[{\char`\"{}osmo\+\_\+hexdump\+\_\+nospc\char`\"{}}]{ }\end{DoxyParamCaption})}

\mbox{\label{group__utils_ga4df5d6ff3d338b9cf4ca59d2cc884d7f}} 
\index{General-\/purpose utility functions@{General-\/purpose utility functions}!get\_string\_value@{get\_string\_value}}
\index{get\_string\_value@{get\_string\_value}!General-\/purpose utility functions@{General-\/purpose utility functions}}
\doxysubsubsection{get\_string\_value()}
{\footnotesize\ttfamily int get\+\_\+string\+\_\+value (\begin{DoxyParamCaption}\item[{const struct \textbf{ value\+\_\+string} $\ast$}]{vs,  }\item[{const char $\ast$}]{str }\end{DoxyParamCaption})}



get numeric value for given human-\/readable string 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em vs} & Array of \doxyref{value\+\_\+string}{p.}{structvalue__string} tuples \\
\hline
\mbox{\texttt{ in}}  & {\em str} & human-\/readable string \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
numeric value ($>$0) or negative numer in case of error 
\end{DoxyReturn}


References \textbf{ value\+\_\+string\+::value}.



Referenced by \textbf{ log\+\_\+parse\+\_\+level()}.

\mbox{\label{group__utils_gaf5e6416f5d73a1ff2e7bdb0e434d10d7}} 
\index{General-\/purpose utility functions@{General-\/purpose utility functions}!get\_value\_string@{get\_value\_string}}
\index{get\_value\_string@{get\_value\_string}!General-\/purpose utility functions@{General-\/purpose utility functions}}
\doxysubsubsection{get\_value\_string()}
{\footnotesize\ttfamily const char $\ast$ get\+\_\+value\+\_\+string (\begin{DoxyParamCaption}\item[{const struct \textbf{ value\+\_\+string} $\ast$}]{vs,  }\item[{uint32\+\_\+t}]{val }\end{DoxyParamCaption})}



get human-\/readable string for given value 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em vs} & Array of \doxyref{value\+\_\+string}{p.}{structvalue__string} tuples \\
\hline
\mbox{\texttt{ in}}  & {\em val} & Value to be converted \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
pointer to human-\/readable string
\end{DoxyReturn}
If val is found in vs, the array\textquotesingle{}s string entry is returned. Otherwise, an \char`\"{}unknown\char`\"{} string containing the actual value is composed in a static buffer that is reused across invocations. 

References \textbf{ get\+\_\+value\+\_\+string\+\_\+or\+\_\+null()}, and \textbf{ namebuf}.



Referenced by \textbf{ level\+\_\+color()}, \textbf{ log\+\_\+level\+\_\+str()}, \textbf{ osmo\+\_\+fsm\+\_\+event\+\_\+name()}, \textbf{ osmo\+\_\+fsm\+\_\+term\+\_\+cause\+\_\+name()}, \textbf{ osmo\+\_\+io\+\_\+backend\+\_\+name()}, \textbf{ osmo\+\_\+iofd\+\_\+mode\+\_\+name()}, \textbf{ osmo\+\_\+prim\+\_\+operation\+\_\+name()}, and \textbf{ osmo\+\_\+tdef\+\_\+unit\+\_\+name()}.

\mbox{\label{group__utils_gac44be7d0bc776c31efd951653bcbe0cd}} 
\index{General-\/purpose utility functions@{General-\/purpose utility functions}!get\_value\_string\_or\_null@{get\_value\_string\_or\_null}}
\index{get\_value\_string\_or\_null@{get\_value\_string\_or\_null}!General-\/purpose utility functions@{General-\/purpose utility functions}}
\doxysubsubsection{get\_value\_string\_or\_null()}
{\footnotesize\ttfamily const char $\ast$ get\+\_\+value\+\_\+string\+\_\+or\+\_\+null (\begin{DoxyParamCaption}\item[{const struct \textbf{ value\+\_\+string} $\ast$}]{vs,  }\item[{uint32\+\_\+t}]{val }\end{DoxyParamCaption})}



get human-\/readable string or NULL for given value 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em vs} & Array of \doxyref{value\+\_\+string}{p.}{structvalue__string} tuples \\
\hline
\mbox{\texttt{ in}}  & {\em val} & Value to be converted \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
pointer to human-\/readable string or NULL if val is not found 
\end{DoxyReturn}


References \textbf{ value\+\_\+string\+::str}.



Referenced by \textbf{ get\+\_\+value\+\_\+string()}, and \textbf{ level\+\_\+color()}.

\mbox{\label{group__utils_gaaf78cfb7a88674f118451b9279306c22}} 
\index{General-\/purpose utility functions@{General-\/purpose utility functions}!osmo\_bcd2char@{osmo\_bcd2char}}
\index{osmo\_bcd2char@{osmo\_bcd2char}!General-\/purpose utility functions@{General-\/purpose utility functions}}
\doxysubsubsection{osmo\_bcd2char()}
{\footnotesize\ttfamily char osmo\+\_\+bcd2char (\begin{DoxyParamCaption}\item[{uint8\+\_\+t}]{bcd }\end{DoxyParamCaption})}



Convert BCD-\/encoded digit into printable character. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em bcd} & A single BCD-\/encoded digit \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
single printable character 
\end{DoxyReturn}


Referenced by \textbf{ osmo\+\_\+bcd2str()}.

\mbox{\label{group__utils_ga422bbc07222f809d350ad39fb894c803}} 
\index{General-\/purpose utility functions@{General-\/purpose utility functions}!osmo\_bcd2str@{osmo\_bcd2str}}
\index{osmo\_bcd2str@{osmo\_bcd2str}!General-\/purpose utility functions@{General-\/purpose utility functions}}
\doxysubsubsection{osmo\_bcd2str()}
{\footnotesize\ttfamily int osmo\+\_\+bcd2str (\begin{DoxyParamCaption}\item[{char $\ast$}]{dst,  }\item[{size\+\_\+t}]{dst\+\_\+size,  }\item[{const uint8\+\_\+t $\ast$}]{bcd,  }\item[{int}]{start\+\_\+nibble,  }\item[{int}]{end\+\_\+nibble,  }\item[{bool}]{allow\+\_\+hex }\end{DoxyParamCaption})}



Convert BCD to string. 

The given nibble offsets are interpreted in BCD order, i.\+e. nibble 0 is bcd[0] \& 0xf, nibble 1 is bcd[0] $>$$>$ 4, nibble 3 is bcd[1] \& 0xf, etc.. 
\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ out}}  & {\em dst} & Output string buffer, is always nul terminated when dst\+\_\+size $>$ 0. \\
\hline
\mbox{\texttt{ in}}  & {\em dst\+\_\+size} & sizeof() the output string buffer. \\
\hline
\mbox{\texttt{ in}}  & {\em bcd} & Binary coded data buffer. \\
\hline
\mbox{\texttt{ in}}  & {\em start\+\_\+nibble} & Offset to start from, in nibbles, typically 1 to skip the first nibble. \\
\hline
\mbox{\texttt{ in}}  & {\em end\+\_\+nibble} & Offset to stop before, in nibbles, e.\+g. sizeof(bcd)$\ast$2 -\/ (bcd[0] \& GSM\+\_\+\+MI\+\_\+\+ODD? 0\+:1). \\
\hline
\mbox{\texttt{ in}}  & {\em allow\+\_\+hex} & If false, return error if there are digits other than 0-\/9. If true, return those as [A-\/F]. \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
The strlen that would be written if the output buffer is large enough, excluding nul byte (like snprintf()), or -\/EINVAL if allow\+\_\+hex is false and a digit $>$ 9 is encountered. On -\/EINVAL, the conversion is still completed as if allow\+\_\+hex were passed as true. Return -\/ENOMEM if dst is NULL or dst\+\_\+size is zero. If end\+\_\+nibble $<$= start\+\_\+nibble, write an empty string to dst and return 0. 
\end{DoxyReturn}


References \textbf{ osmo\+\_\+bcd2char()}, and \textbf{ OSMO\+\_\+\+MAX}.

\mbox{\label{group__utils_gae5cbea0fd5e1594354d115912d46454c}} 
\index{General-\/purpose utility functions@{General-\/purpose utility functions}!osmo\_char2bcd@{osmo\_char2bcd}}
\index{osmo\_char2bcd@{osmo\_char2bcd}!General-\/purpose utility functions@{General-\/purpose utility functions}}
\doxysubsubsection{osmo\_char2bcd()}
{\footnotesize\ttfamily uint8\+\_\+t osmo\+\_\+char2bcd (\begin{DoxyParamCaption}\item[{char}]{c }\end{DoxyParamCaption})}



Convert number in ASCII to BCD value. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em c} & ASCII character \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
BCD encoded value of character 
\end{DoxyReturn}


References \textbf{ c}.

\mbox{\label{group__utils_ga9617b49a3abc34328ce8fa3eafcdc938}} 
\index{General-\/purpose utility functions@{General-\/purpose utility functions}!osmo\_constant\_time\_cmp@{osmo\_constant\_time\_cmp}}
\index{osmo\_constant\_time\_cmp@{osmo\_constant\_time\_cmp}!General-\/purpose utility functions@{General-\/purpose utility functions}}
\doxysubsubsection{osmo\_constant\_time\_cmp()}
{\footnotesize\ttfamily int osmo\+\_\+constant\+\_\+time\+\_\+cmp (\begin{DoxyParamCaption}\item[{const uint8\+\_\+t $\ast$}]{exp,  }\item[{const uint8\+\_\+t $\ast$}]{rel,  }\item[{const int}]{count }\end{DoxyParamCaption})}



Wishful thinking to generate a constant time compare. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em exp} & Expected data \\
\hline
\mbox{\texttt{ in}}  & {\em rel} & Comparison value \\
\hline
\mbox{\texttt{ in}}  & {\em count} & Number of bytes to compare \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
1 in case {\itshape exp} equals {\itshape rel}; zero otherwise
\end{DoxyReturn}
Compare count bytes of exp to rel. Return 0 if they are identical, 1 otherwise. Do not return a mismatch on the first mismatching byte, but always compare all bytes, regardless. The idea is that the amount of matching bytes cannot be inferred from the time the comparison took. 

References \textbf{ x}.

\mbox{\label{group__utils_ga527e54191de66b00edd22500017da9ad}} 
\index{General-\/purpose utility functions@{General-\/purpose utility functions}!osmo\_decode\_big\_endian@{osmo\_decode\_big\_endian}}
\index{osmo\_decode\_big\_endian@{osmo\_decode\_big\_endian}!General-\/purpose utility functions@{General-\/purpose utility functions}}
\doxysubsubsection{osmo\_decode\_big\_endian()}
{\footnotesize\ttfamily uint64\+\_\+t osmo\+\_\+decode\+\_\+big\+\_\+endian (\begin{DoxyParamCaption}\item[{const uint8\+\_\+t $\ast$}]{data,  }\item[{size\+\_\+t}]{data\+\_\+len }\end{DoxyParamCaption})}



Generic retrieval of 1..8 bytes as big-\/endian uint64\+\_\+t. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em data} & Input data as byte-\/array \\
\hline
\mbox{\texttt{ in}}  & {\em data\+\_\+len} & Length of {\itshape data} in octets \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
uint64\+\_\+t of {\itshape data} interpreted as big-\/endian
\end{DoxyReturn}
This is like osmo\+\_\+load64be\+\_\+ext, except that if data\+\_\+len is less than sizeof(uint64\+\_\+t), the data is interpreted as the least significant bytes (osmo\+\_\+load64be\+\_\+ext loads them as the most significant bytes into the returned uint64\+\_\+t). In this way, any integer size up to 64 bits can be decoded conveniently by using sizeof(), without the need to call specific numbered functions (osmo\+\_\+load16, 32, ...). 

References \textbf{ data}.

\mbox{\label{group__utils_gab461793c9157461119e621710f3f340c}} 
\index{General-\/purpose utility functions@{General-\/purpose utility functions}!osmo\_encode\_big\_endian@{osmo\_encode\_big\_endian}}
\index{osmo\_encode\_big\_endian@{osmo\_encode\_big\_endian}!General-\/purpose utility functions@{General-\/purpose utility functions}}
\doxysubsubsection{osmo\_encode\_big\_endian()}
{\footnotesize\ttfamily uint8\+\_\+t $\ast$ osmo\+\_\+encode\+\_\+big\+\_\+endian (\begin{DoxyParamCaption}\item[{uint64\+\_\+t}]{value,  }\item[{size\+\_\+t}]{data\+\_\+len }\end{DoxyParamCaption})}



Generic big-\/endian encoding of big endian number up to 64bit. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em value} & unsigned integer value to be stored \\
\hline
\mbox{\texttt{ in}}  & {\em data\+\_\+len} & number of octets \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
static buffer containing big-\/endian stored value
\end{DoxyReturn}
This is like osmo\+\_\+store64be\+\_\+ext, except that this returns a static buffer of the result (for convenience, but not threadsafe). If data\+\_\+len is less than sizeof(uint64\+\_\+t), only the least significant bytes of value are encoded. 

References \textbf{ ARRAY\+\_\+\+SIZE}, \textbf{ OSMO\+\_\+\+ASSERT}, and \textbf{ osmo\+\_\+store64be\+\_\+ext()}.

\mbox{\label{group__utils_gab2348926540f8c8a56f4e6a17c996f7f}} 
\index{General-\/purpose utility functions@{General-\/purpose utility functions}!osmo\_escape\_cstr\_buf@{osmo\_escape\_cstr\_buf}}
\index{osmo\_escape\_cstr\_buf@{osmo\_escape\_cstr\_buf}!General-\/purpose utility functions@{General-\/purpose utility functions}}
\doxysubsubsection{osmo\_escape\_cstr\_buf()}
{\footnotesize\ttfamily size\+\_\+t osmo\+\_\+escape\+\_\+cstr\+\_\+buf (\begin{DoxyParamCaption}\item[{char $\ast$}]{buf,  }\item[{size\+\_\+t}]{bufsize,  }\item[{const char $\ast$}]{str,  }\item[{int}]{in\+\_\+len }\end{DoxyParamCaption})}



Return the string with all non-\/printable characters escaped. 

In contrast to \doxyref{osmo\+\_\+escape\+\_\+str\+\_\+buf2()}{p.}{group__utils_gab6d6c37d5cc2807eb63b41498f38fb9d}, this returns the needed buffer size suitable for \doxyref{OSMO\+\_\+\+STRBUF\+\_\+\+APPEND()}{p.}{group__utils_gafff80b7c628a7b9138d0d663f6554de2}, and this escapes characters in a way compatible with C string constant syntax. 
\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ out}}  & {\em buf} & string buffer to write escaped characters to. \\
\hline
\mbox{\texttt{ in}}  & {\em bufsize} & sizeof(buf). \\
\hline
\mbox{\texttt{ in}}  & {\em str} & A string that may contain any characters. \\
\hline
\mbox{\texttt{ in}}  & {\em in\+\_\+len} & Pass -\/1 to print until nul char, or $>$= 0 to force a length (also past nul chars). \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
Number of characters that would be written if bufsize were large enough excluding \textquotesingle{}\textbackslash{}0\textquotesingle{} (like snprintf()). 
\end{DoxyReturn}


References \textbf{ \+\_\+osmo\+\_\+escape\+\_\+str\+\_\+buf()}, and \textbf{ osmo\+\_\+strbuf\+::buf}.

\mbox{\label{group__utils_gab8a8241576fe2a82726e0ac2d2e624f5}} 
\index{General-\/purpose utility functions@{General-\/purpose utility functions}!osmo\_escape\_cstr\_c@{osmo\_escape\_cstr\_c}}
\index{osmo\_escape\_cstr\_c@{osmo\_escape\_cstr\_c}!General-\/purpose utility functions@{General-\/purpose utility functions}}
\doxysubsubsection{osmo\_escape\_cstr\_c()}
{\footnotesize\ttfamily char $\ast$ osmo\+\_\+escape\+\_\+cstr\+\_\+c (\begin{DoxyParamCaption}\item[{void $\ast$}]{ctx,  }\item[{const char $\ast$}]{str,  }\item[{int}]{in\+\_\+len }\end{DoxyParamCaption})}



Return the string with all non-\/printable characters escaped, in dynamically-\/allocated buffer. 

In contrast to \doxyref{osmo\+\_\+escape\+\_\+str\+\_\+c()}{p.}{group__utils_ga46ac4f967deb6a2e8c4a1930273bfbbd}, this escapes characters in a way compatible with C string constant syntax, and allocates sufficient memory in all cases. 
\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em str} & A string that may contain any characters. \\
\hline
\mbox{\texttt{ in}}  & {\em len} & Pass -\/1 to print until nul char, or $>$= 0 to force a length. \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
dynamically-\/allocated buffer, containing an escaped representation. 
\end{DoxyReturn}


References \textbf{ \+\_\+osmo\+\_\+escape\+\_\+str\+\_\+buf()}, and \textbf{ OSMO\+\_\+\+NAME\+\_\+\+C\+\_\+\+IMPL}.

\mbox{\label{group__utils_gab9fb9032407e96924732bf60f4476195}} 
\index{General-\/purpose utility functions@{General-\/purpose utility functions}!osmo\_escape\_str@{osmo\_escape\_str}}
\index{osmo\_escape\_str@{osmo\_escape\_str}!General-\/purpose utility functions@{General-\/purpose utility functions}}
\doxysubsubsection{osmo\_escape\_str()}
{\footnotesize\ttfamily const char $\ast$ osmo\+\_\+escape\+\_\+str (\begin{DoxyParamCaption}\item[{const char $\ast$}]{str,  }\item[{int}]{in\+\_\+len }\end{DoxyParamCaption})}



Return the string with all non-\/printable characters escaped. 

Call \doxyref{osmo\+\_\+escape\+\_\+str\+\_\+buf()}{p.}{group__utils_gad3cf1d094e625a962737b4ba9c2a5632} with a static buffer. 
\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em str} & A string that may contain any characters. \\
\hline
\mbox{\texttt{ in}}  & {\em len} & Pass -\/1 to print until nul char, or $>$= 0 to force a length. \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
buf containing an escaped representation, possibly truncated, or str itself. 
\end{DoxyReturn}


References \textbf{ namebuf}, and \textbf{ osmo\+\_\+escape\+\_\+str\+\_\+buf()}.

\mbox{\label{group__utils_gad3cf1d094e625a962737b4ba9c2a5632}} 
\index{General-\/purpose utility functions@{General-\/purpose utility functions}!osmo\_escape\_str\_buf@{osmo\_escape\_str\_buf}}
\index{osmo\_escape\_str\_buf@{osmo\_escape\_str\_buf}!General-\/purpose utility functions@{General-\/purpose utility functions}}
\doxysubsubsection{osmo\_escape\_str\_buf()}
{\footnotesize\ttfamily const char $\ast$ osmo\+\_\+escape\+\_\+str\+\_\+buf (\begin{DoxyParamCaption}\item[{const char $\ast$}]{str,  }\item[{int}]{in\+\_\+len,  }\item[{char $\ast$}]{buf,  }\item[{size\+\_\+t}]{bufsize }\end{DoxyParamCaption})}



Like osmo\+\_\+escape\+\_\+str\+\_\+buf2, but with unusual ordering of arguments, and may sometimes return string constants instead of writing to buf for error cases or empty input. 

Most $\ast$\+\_\+buf() functions have the buffer and size as first arguments, here the arguments are last. In particular, this function signature doesn\textquotesingle{}t work with \doxyref{OSMO\+\_\+\+STRBUF\+\_\+\+APPEND\+\_\+\+NOLEN()}{p.}{group__utils_gaba053478cf0abc6d10ada0851e796a4b}. 
\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em str} & A string that may contain any characters. \\
\hline
\mbox{\texttt{ in}}  & {\em len} & Pass -\/1 to print until nul char, or $>$= 0 to force a length. \\
\hline
\mbox{\texttt{ in,out}}  & {\em buf} & string buffer to write escaped characters to. \\
\hline
\mbox{\texttt{ in}}  & {\em bufsize} & size of {\itshape buf}. \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
buf containing an escaped representation, possibly truncated, or \char`\"{}(null)\char`\"{} if str == NULL, or \char`\"{}(error)\char`\"{} in case of errors. 
\end{DoxyReturn}


References \textbf{ osmo\+\_\+escape\+\_\+str\+\_\+buf2()}.



Referenced by \textbf{ osmo\+\_\+escape\+\_\+str()}.

\mbox{\label{group__utils_gab6d6c37d5cc2807eb63b41498f38fb9d}} 
\index{General-\/purpose utility functions@{General-\/purpose utility functions}!osmo\_escape\_str\_buf2@{osmo\_escape\_str\_buf2}}
\index{osmo\_escape\_str\_buf2@{osmo\_escape\_str\_buf2}!General-\/purpose utility functions@{General-\/purpose utility functions}}
\doxysubsubsection{osmo\_escape\_str\_buf2()}
{\footnotesize\ttfamily char $\ast$ osmo\+\_\+escape\+\_\+str\+\_\+buf2 (\begin{DoxyParamCaption}\item[{char $\ast$}]{buf,  }\item[{size\+\_\+t}]{bufsize,  }\item[{const char $\ast$}]{str,  }\item[{int}]{in\+\_\+len }\end{DoxyParamCaption})}



Return the string with all non-\/printable characters escaped. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ out}}  & {\em buf} & string buffer to write escaped characters to. \\
\hline
\mbox{\texttt{ in}}  & {\em bufsize} & sizeof(buf). \\
\hline
\mbox{\texttt{ in}}  & {\em str} & A string that may contain any characters. \\
\hline
\mbox{\texttt{ in}}  & {\em in\+\_\+len} & Pass -\/1 to print until nul char, or $>$= 0 to force a length (also past nul chars). \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
The output buffer (buf). 
\end{DoxyReturn}


References \textbf{ \+\_\+osmo\+\_\+escape\+\_\+str\+\_\+buf()}, and \textbf{ osmo\+\_\+strbuf\+::buf}.



Referenced by \textbf{ osmo\+\_\+escape\+\_\+str\+\_\+buf()}.

\mbox{\label{group__utils_ga6b4866958eb385b561fc1fa91db242e7}} 
\index{General-\/purpose utility functions@{General-\/purpose utility functions}!osmo\_escape\_str\_buf3@{osmo\_escape\_str\_buf3}}
\index{osmo\_escape\_str\_buf3@{osmo\_escape\_str\_buf3}!General-\/purpose utility functions@{General-\/purpose utility functions}}
\doxysubsubsection{osmo\_escape\_str\_buf3()}
{\footnotesize\ttfamily int osmo\+\_\+escape\+\_\+str\+\_\+buf3 (\begin{DoxyParamCaption}\item[{char $\ast$}]{buf,  }\item[{size\+\_\+t}]{bufsize,  }\item[{const char $\ast$}]{str,  }\item[{int}]{in\+\_\+len }\end{DoxyParamCaption})}



Return the string with all non-\/printable characters escaped. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ out}}  & {\em buf} & string buffer to write escaped characters to. \\
\hline
\mbox{\texttt{ in}}  & {\em bufsize} & sizeof(buf). \\
\hline
\mbox{\texttt{ in}}  & {\em str} & A string that may contain any characters. \\
\hline
\mbox{\texttt{ in}}  & {\em in\+\_\+len} & Pass -\/1 to print until nul char, or $>$= 0 to force a length (also past nul chars). \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
Number of characters that would be written if bufsize were large enough excluding \textquotesingle{}\textbackslash{}0\textquotesingle{} (like snprintf()). 
\end{DoxyReturn}


References \textbf{ \+\_\+osmo\+\_\+escape\+\_\+str\+\_\+buf()}, and \textbf{ osmo\+\_\+strbuf\+::buf}.

\mbox{\label{group__utils_ga46ac4f967deb6a2e8c4a1930273bfbbd}} 
\index{General-\/purpose utility functions@{General-\/purpose utility functions}!osmo\_escape\_str\_c@{osmo\_escape\_str\_c}}
\index{osmo\_escape\_str\_c@{osmo\_escape\_str\_c}!General-\/purpose utility functions@{General-\/purpose utility functions}}
\doxysubsubsection{osmo\_escape\_str\_c()}
{\footnotesize\ttfamily char $\ast$ osmo\+\_\+escape\+\_\+str\+\_\+c (\begin{DoxyParamCaption}\item[{const void $\ast$}]{ctx,  }\item[{const char $\ast$}]{str,  }\item[{int}]{in\+\_\+len }\end{DoxyParamCaption})}



Return the string with all non-\/printable characters escaped, in dynamically-\/allocated buffer. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em str} & A string that may contain any characters. \\
\hline
\mbox{\texttt{ in}}  & {\em len} & Pass -\/1 to print until nul char, or $>$= 0 to force a length. \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
dynamically-\/allocated output buffer, containing an escaped representation 
\end{DoxyReturn}


References \textbf{ \+\_\+osmo\+\_\+escape\+\_\+str\+\_\+buf()}, and \textbf{ OSMO\+\_\+\+NAME\+\_\+\+C\+\_\+\+IMPL}.

\mbox{\label{group__utils_gaae0fa80cc1a996386d83a5ebb2d57f8b}} 
\index{General-\/purpose utility functions@{General-\/purpose utility functions}!osmo\_float\_str\_to\_int@{osmo\_float\_str\_to\_int}}
\index{osmo\_float\_str\_to\_int@{osmo\_float\_str\_to\_int}!General-\/purpose utility functions@{General-\/purpose utility functions}}
\doxysubsubsection{osmo\_float\_str\_to\_int()}
{\footnotesize\ttfamily int osmo\+\_\+float\+\_\+str\+\_\+to\+\_\+int (\begin{DoxyParamCaption}\item[{int64\+\_\+t $\ast$}]{val,  }\item[{const char $\ast$}]{str,  }\item[{unsigned int}]{precision }\end{DoxyParamCaption})}



Convert a string of a floating point number to a signed int, with a decimal factor (fixed-\/point precision). 

For example, with precision=3, convert \char`\"{}-\/1.\+23\char`\"{} to -\/1230. In other words, the float value is multiplied by 10 to-\/the-\/power-\/of precision to obtain the returned integer. The usable range of digits is -\/INT64\+\_\+\+MAX .. INT64\+\_\+\+MAX -- note, not INT64\+\_\+\+MIN! The value of INT64\+\_\+\+MIN is excluded to reduce implementation complexity. See also utils\+\_\+test.\+c. The advantage over using sscanf(\char`\"{}\%f\char`\"{}) is guaranteed precision\+: float or double types may apply rounding in the conversion result. \doxyref{osmo\+\_\+float\+\_\+str\+\_\+to\+\_\+int()}{p.}{group__utils_gaae0fa80cc1a996386d83a5ebb2d57f8b} and \doxyref{osmo\+\_\+int\+\_\+to\+\_\+float\+\_\+str\+\_\+buf()}{p.}{group__utils_gafbbe67276ab1495e5d05eed369e65d92} guarantee true results when converting back and forth between string and int. 
\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ out}}  & {\em val} & Returned integer value. \\
\hline
\mbox{\texttt{ in}}  & {\em str} & String of a float, like \textquotesingle{}-\/12.\+345\textquotesingle{}. \\
\hline
\mbox{\texttt{ in}}  & {\em precision} & Fixed-\/point precision, or $\ast$ \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
0 on success, negative on error. 
\end{DoxyReturn}


References \textbf{ OSMO\+\_\+\+ASSERT}, \textbf{ osmo\+\_\+strlcpy()}, and \textbf{ point}.

\mbox{\label{group__utils_ga570ff719ef3bd624bffa17e1ddba0f78}} 
\index{General-\/purpose utility functions@{General-\/purpose utility functions}!osmo\_get\_macaddr@{osmo\_get\_macaddr}}
\index{osmo\_get\_macaddr@{osmo\_get\_macaddr}!General-\/purpose utility functions@{General-\/purpose utility functions}}
\doxysubsubsection{osmo\_get\_macaddr()}
{\footnotesize\ttfamily int osmo\+\_\+get\+\_\+macaddr (\begin{DoxyParamCaption}\item[{uint8\+\_\+t $\ast$}]{mac\+\_\+out,  }\item[{const char $\ast$}]{dev\+\_\+name }\end{DoxyParamCaption})}



Obtain the MAC address of a given network device. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ out}}  & {\em mac\+\_\+out} & pointer to caller-\/allocated buffer of 6 bytes \\
\hline
\mbox{\texttt{ in}}  & {\em dev\+\_\+name} & string name of the network device \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
0 in case of success; negative otherwise 
\end{DoxyReturn}
\mbox{\label{group__utils_gadfc3801536ff055305f7b2563539237f}} 
\index{General-\/purpose utility functions@{General-\/purpose utility functions}!osmo\_hexdump@{osmo\_hexdump}}
\index{osmo\_hexdump@{osmo\_hexdump}!General-\/purpose utility functions@{General-\/purpose utility functions}}
\doxysubsubsection{osmo\_hexdump()}
{\footnotesize\ttfamily char $\ast$ osmo\+\_\+hexdump (\begin{DoxyParamCaption}\item[{const unsigned char $\ast$}]{buf,  }\item[{int}]{len }\end{DoxyParamCaption})}



Convert binary sequence to hexadecimal ASCII string. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em buf} & pointer to sequence of bytes \\
\hline
\mbox{\texttt{ in}}  & {\em len} & length of buf in number of bytes \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
pointer to zero-\/terminated string
\end{DoxyReturn}
This function will print a sequence of bytes as hexadecimal numbers, adding one space character between each byte (e.\+g. \char`\"{}1a ef d9\char`\"{})

The maximum size of the output buffer is 4096 bytes, i.\+e. the maximum number of input bytes that can be printed in one call is 1365! 

References \textbf{ hexd\+\_\+buff}, \textbf{ len()}, and \textbf{ osmo\+\_\+hexdump\+\_\+buf()}.



Referenced by \textbf{ \+\_\+msgb\+\_\+eq()}, \textbf{ msgb\+\_\+hexdump\+\_\+buf()}, \textbf{ msgb\+\_\+hexdump\+\_\+l1()}, \textbf{ msgb\+\_\+hexdump\+\_\+l2()}, \textbf{ msgb\+\_\+hexdump\+\_\+l3()}, and \textbf{ msgb\+\_\+hexdump\+\_\+l4()}.

\mbox{\label{group__utils_ga2dd24d5b9cab288e90a2067c8dbc9a78}} 
\index{General-\/purpose utility functions@{General-\/purpose utility functions}!osmo\_hexdump\_buf@{osmo\_hexdump\_buf}}
\index{osmo\_hexdump\_buf@{osmo\_hexdump\_buf}!General-\/purpose utility functions@{General-\/purpose utility functions}}
\doxysubsubsection{osmo\_hexdump\_buf()}
{\footnotesize\ttfamily const char $\ast$ osmo\+\_\+hexdump\+\_\+buf (\begin{DoxyParamCaption}\item[{char $\ast$}]{out\+\_\+buf,  }\item[{size\+\_\+t}]{out\+\_\+buf\+\_\+size,  }\item[{const unsigned char $\ast$}]{buf,  }\item[{int}]{len,  }\item[{const char $\ast$}]{delim,  }\item[{bool}]{delim\+\_\+after\+\_\+last }\end{DoxyParamCaption})}



Convert binary sequence to hexadecimal ASCII string. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ out}}  & {\em out\+\_\+buf} & Output buffer to write the resulting string to. \\
\hline
\mbox{\texttt{ in}}  & {\em out\+\_\+buf\+\_\+size} & sizeof(out\+\_\+buf). \\
\hline
\mbox{\texttt{ in}}  & {\em buf} & Input buffer, pointer to sequence of bytes. \\
\hline
\mbox{\texttt{ in}}  & {\em len} & Length of input buf in number of bytes. \\
\hline
\mbox{\texttt{ in}}  & {\em delim} & String to separate each byte; NULL or \char`\"{}\char`\"{} for no delim. \\
\hline
\mbox{\texttt{ in}}  & {\em delim\+\_\+after\+\_\+last} & If true, end the string in delim (true\+: \char`\"{}1a\+:ef\+:d9\+:\char`\"{}, false\+: \char`\"{}1a\+:ef\+:d9\char`\"{}); if out\+\_\+buf has insufficient space, the string will always end in a delim. \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
out\+\_\+buf, containing a zero-\/terminated string, or \char`\"{}\char`\"{} (empty string) if out\+\_\+buf == NULL or out\+\_\+buf\+\_\+size $<$ 1.
\end{DoxyReturn}
This function will print a sequence of bytes as hexadecimal numbers, adding one delim between each byte (e.\+g. for delim passed as \char`\"{}\+:\char`\"{}, return a string like \char`\"{}1a\+:ef\+:d9\char`\"{}).

The delim\+\_\+after\+\_\+last argument exists to be able to exactly show the original \doxyref{osmo\+\_\+hexdump()}{p.}{group__utils_gadfc3801536ff055305f7b2563539237f} behavior, which always ends the string with a delimiter. 

References \textbf{ hex\+\_\+chars}, and \textbf{ len()}.



Referenced by \textbf{ osmo\+\_\+hexdump()}, \textbf{ osmo\+\_\+hexdump\+\_\+c()}, \textbf{ osmo\+\_\+hexdump\+\_\+nospc()}, and \textbf{ osmo\+\_\+hexdump\+\_\+nospc\+\_\+c()}.

\mbox{\label{group__utils_gae0e18c985d66a2affda7e8ab54a13f9e}} 
\index{General-\/purpose utility functions@{General-\/purpose utility functions}!osmo\_hexdump\_c@{osmo\_hexdump\_c}}
\index{osmo\_hexdump\_c@{osmo\_hexdump\_c}!General-\/purpose utility functions@{General-\/purpose utility functions}}
\doxysubsubsection{osmo\_hexdump\_c()}
{\footnotesize\ttfamily char $\ast$ osmo\+\_\+hexdump\+\_\+c (\begin{DoxyParamCaption}\item[{const void $\ast$}]{ctx,  }\item[{const unsigned char $\ast$}]{buf,  }\item[{int}]{len }\end{DoxyParamCaption})}



Convert binary sequence to hexadecimal ASCII string. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em ctx} & talloc context from where to allocate the output string \\
\hline
\mbox{\texttt{ in}}  & {\em buf} & pointer to sequence of bytes \\
\hline
\mbox{\texttt{ in}}  & {\em len} & length of buf in number of bytes \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
pointer to zero-\/terminated string
\end{DoxyReturn}
This function will print a sequence of bytes as hexadecimal numbers, adding one space character between each byte (e.\+g. \char`\"{}1a ef d9\char`\"{}) 

References \textbf{ hexd\+\_\+buff}, \textbf{ len()}, and \textbf{ osmo\+\_\+hexdump\+\_\+buf()}.

\mbox{\label{group__utils_ga58cacabcd4862f29a9aa57dd2627c976}} 
\index{General-\/purpose utility functions@{General-\/purpose utility functions}!osmo\_hexdump\_nospc@{osmo\_hexdump\_nospc}}
\index{osmo\_hexdump\_nospc@{osmo\_hexdump\_nospc}!General-\/purpose utility functions@{General-\/purpose utility functions}}
\doxysubsubsection{osmo\_hexdump\_nospc()}
{\footnotesize\ttfamily char $\ast$ osmo\+\_\+hexdump\+\_\+nospc (\begin{DoxyParamCaption}\item[{const unsigned char $\ast$}]{buf,  }\item[{int}]{len }\end{DoxyParamCaption})}



Convert binary sequence to hexadecimal ASCII string. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em buf} & pointer to sequence of bytes \\
\hline
\mbox{\texttt{ in}}  & {\em len} & length of buf in number of bytes \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
pointer to zero-\/terminated string
\end{DoxyReturn}
This function will print a sequence of bytes as hexadecimal numbers, without any space character between each byte (e.\+g. \char`\"{}1aefd9\char`\"{})

The maximum size of the output buffer is 4096 bytes, i.\+e. the maximum number of input bytes that can be printed in one call is 2048! 

References \textbf{ hexd\+\_\+buff}, \textbf{ len()}, and \textbf{ osmo\+\_\+hexdump\+\_\+buf()}.

\mbox{\label{group__utils_gaedfb568cb4c765446cc1beab4db24b5c}} 
\index{General-\/purpose utility functions@{General-\/purpose utility functions}!osmo\_hexdump\_nospc\_c@{osmo\_hexdump\_nospc\_c}}
\index{osmo\_hexdump\_nospc\_c@{osmo\_hexdump\_nospc\_c}!General-\/purpose utility functions@{General-\/purpose utility functions}}
\doxysubsubsection{osmo\_hexdump\_nospc\_c()}
{\footnotesize\ttfamily char $\ast$ osmo\+\_\+hexdump\+\_\+nospc\+\_\+c (\begin{DoxyParamCaption}\item[{const void $\ast$}]{ctx,  }\item[{const unsigned char $\ast$}]{buf,  }\item[{int}]{len }\end{DoxyParamCaption})}



Convert binary sequence to hexadecimal ASCII string. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em ctx} & talloc context from where to allocate the output string \\
\hline
\mbox{\texttt{ in}}  & {\em buf} & pointer to sequence of bytes \\
\hline
\mbox{\texttt{ in}}  & {\em len} & length of buf in number of bytes \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
pointer to zero-\/terminated string
\end{DoxyReturn}
This function will print a sequence of bytes as hexadecimal numbers, without any space character between each byte (e.\+g. \char`\"{}1aefd9\char`\"{}) 

References \textbf{ hexd\+\_\+buff}, \textbf{ len()}, and \textbf{ osmo\+\_\+hexdump\+\_\+buf()}.

\mbox{\label{group__utils_gaa417dc14b499d59106491b55a1c74b62}} 
\index{General-\/purpose utility functions@{General-\/purpose utility functions}!osmo\_hexparse@{osmo\_hexparse}}
\index{osmo\_hexparse@{osmo\_hexparse}!General-\/purpose utility functions@{General-\/purpose utility functions}}
\doxysubsubsection{osmo\_hexparse()}
{\footnotesize\ttfamily int osmo\+\_\+hexparse (\begin{DoxyParamCaption}\item[{const char $\ast$}]{str,  }\item[{uint8\+\_\+t $\ast$}]{b,  }\item[{unsigned int}]{max\+\_\+len }\end{DoxyParamCaption})}



Parse a string containing hexadecimal digits. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em str} & string containing ASCII encoded hexadecimal digits \\
\hline
\mbox{\texttt{ out}}  & {\em b} & output buffer \\
\hline
\mbox{\texttt{ in}}  & {\em max\+\_\+len} & maximum space in output buffer \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
number of parsed octets, or -\/1 on error 
\end{DoxyReturn}


References \textbf{ c}.



Referenced by \textbf{ bitvec\+\_\+unhex()}.

\mbox{\label{group__utils_ga7165f91d0b488d150f8ba3bc83cba590}} 
\index{General-\/purpose utility functions@{General-\/purpose utility functions}!osmo\_identifier\_sanitize\_buf@{osmo\_identifier\_sanitize\_buf}}
\index{osmo\_identifier\_sanitize\_buf@{osmo\_identifier\_sanitize\_buf}!General-\/purpose utility functions@{General-\/purpose utility functions}}
\doxysubsubsection{osmo\_identifier\_sanitize\_buf()}
{\footnotesize\ttfamily void osmo\+\_\+identifier\+\_\+sanitize\+\_\+buf (\begin{DoxyParamCaption}\item[{char $\ast$}]{str,  }\item[{const char $\ast$}]{sep\+\_\+chars,  }\item[{char}]{replace\+\_\+with }\end{DoxyParamCaption})}



Replace characters in the given string buffer so that it is guaranteed to pass \doxyref{osmo\+\_\+separated\+\_\+identifiers\+\_\+valid()}{p.}{group__utils_gabac697c1ef493cb5691eb5f11c4af984}. 

To guarantee passing \doxyref{osmo\+\_\+separated\+\_\+identifiers\+\_\+valid()}{p.}{group__utils_gabac697c1ef493cb5691eb5f11c4af984}, replace\+\_\+with must not itself be an illegal character. If in doubt, use \textquotesingle{}-\/\textquotesingle{}. 
\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in,out}}  & {\em str} & Identifier to sanitize, must be nul terminated and in a writable buffer. \\
\hline
\mbox{\texttt{ in}}  & {\em sep\+\_\+chars} & Additional characters that are to be replaced besides osmo\+\_\+identifier\+\_\+illegal\+\_\+chars. \\
\hline
\mbox{\texttt{ in}}  & {\em replace\+\_\+with} & Replace any illegal characters with this character. \\
\hline
\end{DoxyParams}


References \textbf{ osmo\+\_\+identifier\+\_\+illegal\+\_\+chars}.



Referenced by \textbf{ osmo\+\_\+fsm\+\_\+inst\+\_\+update\+\_\+id\+\_\+f\+\_\+sanitize()}.

\mbox{\label{group__utils_gadfd0a4c05af8693393a7d0afa6899ff3}} 
\index{General-\/purpose utility functions@{General-\/purpose utility functions}!osmo\_identifier\_valid@{osmo\_identifier\_valid}}
\index{osmo\_identifier\_valid@{osmo\_identifier\_valid}!General-\/purpose utility functions@{General-\/purpose utility functions}}
\doxysubsubsection{osmo\_identifier\_valid()}
{\footnotesize\ttfamily bool osmo\+\_\+identifier\+\_\+valid (\begin{DoxyParamCaption}\item[{const char $\ast$}]{str }\end{DoxyParamCaption})}



Determine if a given identifier is valid, i.\+e. 

doesn\textquotesingle{}t contain illegal chars 
\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em str} & String to validate \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
true in case {\itshape str} contains valid identifier, false otherwise 
\end{DoxyReturn}


References \textbf{ osmo\+\_\+separated\+\_\+identifiers\+\_\+valid()}.



Referenced by \textbf{ osmo\+\_\+fsm\+\_\+inst\+\_\+update\+\_\+id\+\_\+f()}, \textbf{ osmo\+\_\+fsm\+\_\+register()}, and \textbf{ rate\+\_\+ctrl\+\_\+group\+\_\+desc\+\_\+validate()}.

\mbox{\label{group__utils_gafbbe67276ab1495e5d05eed369e65d92}} 
\index{General-\/purpose utility functions@{General-\/purpose utility functions}!osmo\_int\_to\_float\_str\_buf@{osmo\_int\_to\_float\_str\_buf}}
\index{osmo\_int\_to\_float\_str\_buf@{osmo\_int\_to\_float\_str\_buf}!General-\/purpose utility functions@{General-\/purpose utility functions}}
\doxysubsubsection{osmo\_int\_to\_float\_str\_buf()}
{\footnotesize\ttfamily int osmo\+\_\+int\+\_\+to\+\_\+float\+\_\+str\+\_\+buf (\begin{DoxyParamCaption}\item[{char $\ast$}]{buf,  }\item[{size\+\_\+t}]{buflen,  }\item[{int64\+\_\+t}]{val,  }\item[{unsigned int}]{precision }\end{DoxyParamCaption})}



Convert an integer to a floating point string using a decimal quotient (fixed-\/point precision). 

For example, with precision = 3, convert -\/1230 to \char`\"{}-\/1.\+23\char`\"{}. The usable range of digits is -\/INT64\+\_\+\+MAX .. INT64\+\_\+\+MAX -- note, not INT64\+\_\+\+MIN! The value of INT64\+\_\+\+MIN is excluded to reduce implementation complexity. See also utils\+\_\+test.\+c. The advantage over using printf(\char`\"{}\%.\+6g\char`\"{}) is guaranteed precision\+: float or double types may apply rounding in the conversion result. \doxyref{osmo\+\_\+float\+\_\+str\+\_\+to\+\_\+int()}{p.}{group__utils_gaae0fa80cc1a996386d83a5ebb2d57f8b} and \doxyref{osmo\+\_\+int\+\_\+to\+\_\+float\+\_\+str\+\_\+buf()}{p.}{group__utils_gafbbe67276ab1495e5d05eed369e65d92} guarantee true results when converting back and forth between string and int. The resulting string omits trailing zeros in the fractional part (like \char`\"{}\%g\char`\"{} would) but never applies rounding. 
\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ out}}  & {\em buf} & Buffer to write string to. \\
\hline
\mbox{\texttt{ in}}  & {\em buflen} & sizeof(buf). \\
\hline
\mbox{\texttt{ in}}  & {\em val} & Value to convert to float. \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
number of chars that would be written, like snprintf(). 
\end{DoxyReturn}


References \textbf{ osmo\+\_\+strbuf\+::buf}, \textbf{ osmo\+\_\+strbuf\+::chars\+\_\+needed}, and \textbf{ OSMO\+\_\+\+STRBUF\+\_\+\+PRINTF}.



Referenced by \textbf{ osmo\+\_\+int\+\_\+to\+\_\+float\+\_\+str\+\_\+c()}.

\mbox{\label{group__utils_ga89e052fb363e9a8b00a686c6f3db0126}} 
\index{General-\/purpose utility functions@{General-\/purpose utility functions}!osmo\_int\_to\_float\_str\_c@{osmo\_int\_to\_float\_str\_c}}
\index{osmo\_int\_to\_float\_str\_c@{osmo\_int\_to\_float\_str\_c}!General-\/purpose utility functions@{General-\/purpose utility functions}}
\doxysubsubsection{osmo\_int\_to\_float\_str\_c()}
{\footnotesize\ttfamily char $\ast$ osmo\+\_\+int\+\_\+to\+\_\+float\+\_\+str\+\_\+c (\begin{DoxyParamCaption}\item[{void $\ast$}]{ctx,  }\item[{int64\+\_\+t}]{val,  }\item[{unsigned int}]{precision }\end{DoxyParamCaption})}



Convert an integer with a factor of a million to a floating point string. 

For example, convert -\/1230000 to \char`\"{}-\/1.\+23\char`\"{}. 
\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em ctx} & Talloc ctx to allocate string buffer from. \\
\hline
\mbox{\texttt{ in}}  & {\em val} & Value to convert to float. \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
resulting string, dynamically allocated. 
\end{DoxyReturn}


References \textbf{ osmo\+\_\+int\+\_\+to\+\_\+float\+\_\+str\+\_\+buf()}, and \textbf{ OSMO\+\_\+\+NAME\+\_\+\+C\+\_\+\+IMPL}.

\mbox{\label{group__utils_gab40f5a73ddd1f2c641ed0da0ca08093d}} 
\index{General-\/purpose utility functions@{General-\/purpose utility functions}!osmo\_is\_hexstr@{osmo\_is\_hexstr}}
\index{osmo\_is\_hexstr@{osmo\_is\_hexstr}!General-\/purpose utility functions@{General-\/purpose utility functions}}
\doxysubsubsection{osmo\_is\_hexstr()}
{\footnotesize\ttfamily bool osmo\+\_\+is\+\_\+hexstr (\begin{DoxyParamCaption}\item[{const char $\ast$}]{str,  }\item[{int}]{min\+\_\+digits,  }\item[{int}]{max\+\_\+digits,  }\item[{bool}]{require\+\_\+even }\end{DoxyParamCaption})}



Validate that a given string is a hex string within given size limits. 

Note that each hex digit amounts to a nibble, so if checking for a hex string to result in N bytes, pass amount of digits as 2$\ast$N. 
\begin{DoxyParams}{Parameters}
{\em str} & A nul-\/terminated string to validate, or NULL. \\
\hline
{\em min\+\_\+digits} & least permitted amount of digits. \\
\hline
{\em max\+\_\+digits} & most permitted amount of digits. \\
\hline
{\em require\+\_\+even} & if true, require an even amount of digits. \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
true when the hex\+\_\+str contains only hexadecimal digits (no whitespace) and matches the requested length; also true when min\+\_\+digits $<$= 0 and str is NULL. 
\end{DoxyReturn}


References \textbf{ len()}.

\mbox{\label{group__utils_ga96865bcbbc856166d1b0fbbd00bb9e38}} 
\index{General-\/purpose utility functions@{General-\/purpose utility functions}!osmo\_isqrt32@{osmo\_isqrt32}}
\index{osmo\_isqrt32@{osmo\_isqrt32}!General-\/purpose utility functions@{General-\/purpose utility functions}}
\doxysubsubsection{osmo\_isqrt32()}
{\footnotesize\ttfamily uint32\+\_\+t osmo\+\_\+isqrt32 (\begin{DoxyParamCaption}\item[{uint32\+\_\+t}]{x }\end{DoxyParamCaption})}



perform an integer square root operation on unsigned 32bit integer. 

This implementation is taken from \char`\"{}\+Hacker\textquotesingle{}s Delight\char`\"{} Figure 11-\/1 \char`\"{}\+Integer square root, Newton\textquotesingle{}s method\char`\"{}, which can also be found at {\texttt{ http\+://www.\+hackersdelight.\+org/hdcodetxt/isqrt.\+c.\+txt}} 

References \textbf{ x}.

\mbox{\label{group__utils_ga780f2653cc84daa994053e5f54349057}} 
\index{General-\/purpose utility functions@{General-\/purpose utility functions}!osmo\_luhn@{osmo\_luhn}}
\index{osmo\_luhn@{osmo\_luhn}!General-\/purpose utility functions@{General-\/purpose utility functions}}
\doxysubsubsection{osmo\_luhn()}
{\footnotesize\ttfamily char osmo\+\_\+luhn (\begin{DoxyParamCaption}\item[{const char $\ast$}]{in,  }\item[{int}]{in\+\_\+len }\end{DoxyParamCaption})}



Calculate the Luhn checksum (as used for IMEIs). 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em in} & Input digits in ASCII string representation. \\
\hline
\mbox{\texttt{ in}}  & {\em in\+\_\+len} & Count of digits to use for the input (14 for IMEI). \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
checksum char (e.\+g. \textquotesingle{}3\textquotesingle{}); negative on error 
\end{DoxyReturn}
\mbox{\label{group__utils_ga6b5f705acbbc2d4cb226b44af6da4c11}} 
\index{General-\/purpose utility functions@{General-\/purpose utility functions}!osmo\_macaddr\_parse@{osmo\_macaddr\_parse}}
\index{osmo\_macaddr\_parse@{osmo\_macaddr\_parse}!General-\/purpose utility functions@{General-\/purpose utility functions}}
\doxysubsubsection{osmo\_macaddr\_parse()}
{\footnotesize\ttfamily int osmo\+\_\+macaddr\+\_\+parse (\begin{DoxyParamCaption}\item[{uint8\+\_\+t $\ast$}]{out,  }\item[{const char $\ast$}]{in }\end{DoxyParamCaption})}



Parse a MAC address from human-\/readable notation This function parses an ethernet MAC address in the commonly-\/used hex/colon notation (00\+:00\+:00\+:00\+:00\+:00) and generates the binary representation from it. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ out}}  & {\em out} & pointer to caller-\/allocated buffer of 6 bytes \\
\hline
\mbox{\texttt{ in}}  & {\em in} & pointer to input data as string with hex/colon notation \\
\hline
\end{DoxyParams}
\mbox{\label{group__utils_ga8c02a287e85ffb5defb781447366b8b3}} 
\index{General-\/purpose utility functions@{General-\/purpose utility functions}!osmo\_osmo\_hexdump\_nospc@{osmo\_osmo\_hexdump\_nospc}}
\index{osmo\_osmo\_hexdump\_nospc@{osmo\_osmo\_hexdump\_nospc}!General-\/purpose utility functions@{General-\/purpose utility functions}}
\doxysubsubsection{osmo\_osmo\_hexdump\_nospc()}
{\footnotesize\ttfamily char $\ast$ osmo\+\_\+osmo\+\_\+hexdump\+\_\+nospc (\begin{DoxyParamCaption}\item[{const unsigned char $\ast$}]{buf,  }\item[{int}]{len }\end{DoxyParamCaption})}

\mbox{\label{group__utils_gae8ebb6efd9b30d8d8940f6d71dc32833}} 
\index{General-\/purpose utility functions@{General-\/purpose utility functions}!osmo\_panic@{osmo\_panic}}
\index{osmo\_panic@{osmo\_panic}!General-\/purpose utility functions@{General-\/purpose utility functions}}
\doxysubsubsection{osmo\_panic()}
{\footnotesize\ttfamily void osmo\+\_\+panic (\begin{DoxyParamCaption}\item[{const char $\ast$}]{fmt,  }\item[{}]{... }\end{DoxyParamCaption})}



Terminate the current program with a panic. 

You can call this function in case some severely unexpected situation is detected and the program is supposed to terminate in a way that reports the fact that it terminates.

The application can register a panic handler function using \doxyref{osmo\+\_\+set\+\_\+panic\+\_\+handler}{p.}{group__utils_ga68ffd899763d4c8d24a8df1708b3fe9d}. If it doesn\textquotesingle{}t, a default panic handler function is called automatically.

The default function on most systems will generate a backtrace and then abort() the process. 

References \textbf{ osmo\+\_\+panic\+\_\+default()}, and \textbf{ osmo\+\_\+panic\+\_\+handler}.



Referenced by \textbf{ bit\+\_\+value\+\_\+to\+\_\+char()}, and \textbf{ osmo\+\_\+tdefs\+\_\+reset()}.

\mbox{\label{group__utils_ga1a2fe815e479e972592b48d6919b8a4c}} 
\index{General-\/purpose utility functions@{General-\/purpose utility functions}!osmo\_panic\_default@{osmo\_panic\_default}}
\index{osmo\_panic\_default@{osmo\_panic\_default}!General-\/purpose utility functions@{General-\/purpose utility functions}}
\doxysubsubsection{osmo\_panic\_default()}
{\footnotesize\ttfamily static void osmo\+\_\+panic\+\_\+default (\begin{DoxyParamCaption}\item[{const char $\ast$}]{fmt,  }\item[{va\+\_\+list}]{args }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [static]}}



References \textbf{ osmo\+\_\+generate\+\_\+backtrace()}.



Referenced by \textbf{ osmo\+\_\+panic()}.

\mbox{\label{group__utils_ga298853e248d7557902d4c0b6eb400d01}} 
\index{General-\/purpose utility functions@{General-\/purpose utility functions}!osmo\_plugin\_load\_all@{osmo\_plugin\_load\_all}}
\index{osmo\_plugin\_load\_all@{osmo\_plugin\_load\_all}!General-\/purpose utility functions@{General-\/purpose utility functions}}
\doxysubsubsection{osmo\_plugin\_load\_all()}
{\footnotesize\ttfamily int osmo\+\_\+plugin\+\_\+load\+\_\+all (\begin{DoxyParamCaption}\item[{const char $\ast$}]{directory }\end{DoxyParamCaption})}

\mbox{\label{group__utils_ga412b892efd1aa17d024863cd103f3fbc}} 
\index{General-\/purpose utility functions@{General-\/purpose utility functions}!osmo\_print\_n@{osmo\_print\_n}}
\index{osmo\_print\_n@{osmo\_print\_n}!General-\/purpose utility functions@{General-\/purpose utility functions}}
\doxysubsubsection{osmo\_print\_n()}
{\footnotesize\ttfamily int osmo\+\_\+print\+\_\+n (\begin{DoxyParamCaption}\item[{char $\ast$}]{buf,  }\item[{size\+\_\+t}]{bufsize,  }\item[{const char $\ast$}]{str,  }\item[{size\+\_\+t}]{n }\end{DoxyParamCaption})}



Copy N characters to a buffer with a function signature useful for \doxyref{OSMO\+\_\+\+STRBUF\+\_\+\+APPEND()}{p.}{group__utils_gafff80b7c628a7b9138d0d663f6554de2}. 

Similarly to snprintf(), the result is always nul terminated (except if buf is NULL or bufsize is 0). 
\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ out}}  & {\em buf} & Target buffer. \\
\hline
\mbox{\texttt{ in}}  & {\em bufsize} & sizeof(buf). \\
\hline
\mbox{\texttt{ in}}  & {\em str} & String to copy. \\
\hline
\mbox{\texttt{ in}}  & {\em n} & Maximum number of non-\/nul characters to copy. \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
Number of characters that would be written if bufsize were large enough excluding \textquotesingle{}\textbackslash{}0\textquotesingle{} (like snprintf()). 
\end{DoxyReturn}


References \textbf{ n}.



Referenced by \textbf{ \+\_\+osmo\+\_\+escape\+\_\+str\+\_\+buf()}.

\mbox{\label{group__utils_ga20f2471a0f60241c8e63c9ee18217b41}} 
\index{General-\/purpose utility functions@{General-\/purpose utility functions}!osmo\_quote\_cstr\_buf@{osmo\_quote\_cstr\_buf}}
\index{osmo\_quote\_cstr\_buf@{osmo\_quote\_cstr\_buf}!General-\/purpose utility functions@{General-\/purpose utility functions}}
\doxysubsubsection{osmo\_quote\_cstr\_buf()}
{\footnotesize\ttfamily size\+\_\+t osmo\+\_\+quote\+\_\+cstr\+\_\+buf (\begin{DoxyParamCaption}\item[{char $\ast$}]{buf,  }\item[{size\+\_\+t}]{bufsize,  }\item[{const char $\ast$}]{str,  }\item[{int}]{in\+\_\+len }\end{DoxyParamCaption})}



Like \doxyref{osmo\+\_\+escape\+\_\+str\+\_\+buf2()}{p.}{group__utils_gab6d6c37d5cc2807eb63b41498f38fb9d}, but returns double-\/quotes around a string, or \char`\"{}\+NULL\char`\"{} for a NULL string. 

This allows passing any char$\ast$ value and get its C representation as string. The function signature is suitable for \doxyref{OSMO\+\_\+\+STRBUF\+\_\+\+APPEND\+\_\+\+NOLEN()}{p.}{group__utils_gaba053478cf0abc6d10ada0851e796a4b}. In contrast to \doxyref{osmo\+\_\+escape\+\_\+str\+\_\+buf2()}{p.}{group__utils_gab6d6c37d5cc2807eb63b41498f38fb9d}, this returns the needed buffer size suitable for \doxyref{OSMO\+\_\+\+STRBUF\+\_\+\+APPEND()}{p.}{group__utils_gafff80b7c628a7b9138d0d663f6554de2}, and this escapes characters in a way compatible with C string constant syntax. 
\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ out}}  & {\em buf} & string buffer to write escaped characters to. \\
\hline
\mbox{\texttt{ in}}  & {\em bufsize} & sizeof(buf). \\
\hline
\mbox{\texttt{ in}}  & {\em str} & A string that may contain any characters. \\
\hline
\mbox{\texttt{ in}}  & {\em in\+\_\+len} & Pass -\/1 to print until nul char, or $>$= 0 to force a length. \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
Number of characters that would be written if bufsize were large enough excluding \textquotesingle{}\textbackslash{}0\textquotesingle{} (like snprintf()). 
\end{DoxyReturn}


References \textbf{ \+\_\+osmo\+\_\+quote\+\_\+str\+\_\+buf()}, and \textbf{ osmo\+\_\+strbuf\+::buf}.

\mbox{\label{group__utils_ga26e74d38fd7a65f5a6ea35161c656e90}} 
\index{General-\/purpose utility functions@{General-\/purpose utility functions}!osmo\_quote\_cstr\_c@{osmo\_quote\_cstr\_c}}
\index{osmo\_quote\_cstr\_c@{osmo\_quote\_cstr\_c}!General-\/purpose utility functions@{General-\/purpose utility functions}}
\doxysubsubsection{osmo\_quote\_cstr\_c()}
{\footnotesize\ttfamily char $\ast$ osmo\+\_\+quote\+\_\+cstr\+\_\+c (\begin{DoxyParamCaption}\item[{void $\ast$}]{ctx,  }\item[{const char $\ast$}]{str,  }\item[{int}]{in\+\_\+len }\end{DoxyParamCaption})}



Return the string quoted and with all non-\/printable characters escaped, in dynamically-\/allocated buffer. 

In contrast to \doxyref{osmo\+\_\+quote\+\_\+str\+\_\+c()}{p.}{group__utils_ga333f103771c3b46336103b57e2bc047c}, this escapes characters in a way compatible with C string constant syntax, and allocates sufficient memory in all cases. 
\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em str} & A string that may contain any characters. \\
\hline
\mbox{\texttt{ in}}  & {\em len} & Pass -\/1 to print until nul char, or $>$= 0 to force a length. \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
dynamically-\/allocated buffer, containing a quoted and escaped representation. 
\end{DoxyReturn}


References \textbf{ \+\_\+osmo\+\_\+quote\+\_\+str\+\_\+buf()}, and \textbf{ OSMO\+\_\+\+NAME\+\_\+\+C\+\_\+\+IMPL}.

\mbox{\label{group__utils_gab25c98708ddc0828695a54a72c711b62}} 
\index{General-\/purpose utility functions@{General-\/purpose utility functions}!osmo\_quote\_str@{osmo\_quote\_str}}
\index{osmo\_quote\_str@{osmo\_quote\_str}!General-\/purpose utility functions@{General-\/purpose utility functions}}
\doxysubsubsection{osmo\_quote\_str()}
{\footnotesize\ttfamily const char $\ast$ osmo\+\_\+quote\+\_\+str (\begin{DoxyParamCaption}\item[{const char $\ast$}]{str,  }\item[{int}]{in\+\_\+len }\end{DoxyParamCaption})}



Like \doxyref{osmo\+\_\+quote\+\_\+str\+\_\+buf()}{p.}{group__utils_gad5c8e9dbe2d66556fde2a49418d2db89} but returns the result in a static buffer. 

The static buffer is shared with \doxyref{get\+\_\+value\+\_\+string()}{p.}{group__utils_gaf5e6416f5d73a1ff2e7bdb0e434d10d7} and \doxyref{osmo\+\_\+escape\+\_\+str()}{p.}{group__utils_gab9fb9032407e96924732bf60f4476195}. 
\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em str} & A string that may contain any characters. \\
\hline
\mbox{\texttt{ in}}  & {\em in\+\_\+len} & Pass -\/1 to print until nul char, or $>$= 0 to force a length. \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
static buffer containing a quoted and escaped representation, possibly truncated. 
\end{DoxyReturn}


References \textbf{ \+\_\+osmo\+\_\+quote\+\_\+str\+\_\+buf()}, and \textbf{ namebuf}.



Referenced by \textbf{ osmo\+\_\+fsm\+\_\+inst\+\_\+update\+\_\+id\+\_\+f()}.

\mbox{\label{group__utils_gad5c8e9dbe2d66556fde2a49418d2db89}} 
\index{General-\/purpose utility functions@{General-\/purpose utility functions}!osmo\_quote\_str\_buf@{osmo\_quote\_str\_buf}}
\index{osmo\_quote\_str\_buf@{osmo\_quote\_str\_buf}!General-\/purpose utility functions@{General-\/purpose utility functions}}
\doxysubsubsection{osmo\_quote\_str\_buf()}
{\footnotesize\ttfamily const char $\ast$ osmo\+\_\+quote\+\_\+str\+\_\+buf (\begin{DoxyParamCaption}\item[{const char $\ast$}]{str,  }\item[{int}]{in\+\_\+len,  }\item[{char $\ast$}]{buf,  }\item[{size\+\_\+t}]{bufsize }\end{DoxyParamCaption})}



Like osmo\+\_\+quote\+\_\+str\+\_\+buf2, but with unusual ordering of arguments, and may sometimes return string constants instead of writing to buf for error cases or empty input. 

Most $\ast$\+\_\+buf() functions have the buffer and size as first arguments, here the arguments are last. In particular, this function signature doesn\textquotesingle{}t work with \doxyref{OSMO\+\_\+\+STRBUF\+\_\+\+APPEND\+\_\+\+NOLEN()}{p.}{group__utils_gaba053478cf0abc6d10ada0851e796a4b}. 
\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em str} & A string that may contain any characters. \\
\hline
\mbox{\texttt{ in}}  & {\em in\+\_\+len} & Pass -\/1 to print until nul char, or $>$= 0 to force a length. \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
buf containing a quoted and escaped representation, possibly truncated. 
\end{DoxyReturn}


References \textbf{ \+\_\+osmo\+\_\+quote\+\_\+str\+\_\+buf()}, and \textbf{ osmo\+\_\+strbuf\+::buf}.

\mbox{\label{group__utils_ga4f3b36bc5fd6e474f7f4caa67eb966c2}} 
\index{General-\/purpose utility functions@{General-\/purpose utility functions}!osmo\_quote\_str\_buf2@{osmo\_quote\_str\_buf2}}
\index{osmo\_quote\_str\_buf2@{osmo\_quote\_str\_buf2}!General-\/purpose utility functions@{General-\/purpose utility functions}}
\doxysubsubsection{osmo\_quote\_str\_buf2()}
{\footnotesize\ttfamily char $\ast$ osmo\+\_\+quote\+\_\+str\+\_\+buf2 (\begin{DoxyParamCaption}\item[{char $\ast$}]{buf,  }\item[{size\+\_\+t}]{bufsize,  }\item[{const char $\ast$}]{str,  }\item[{int}]{in\+\_\+len }\end{DoxyParamCaption})}



Like \doxyref{osmo\+\_\+escape\+\_\+str\+\_\+buf2()}{p.}{group__utils_gab6d6c37d5cc2807eb63b41498f38fb9d}, but returns double-\/quotes around a string, or \char`\"{}\+NULL\char`\"{} for a NULL string. 

This allows passing any char$\ast$ value and get its C representation as string. The function signature is suitable for \doxyref{OSMO\+\_\+\+STRBUF\+\_\+\+APPEND\+\_\+\+NOLEN()}{p.}{group__utils_gaba053478cf0abc6d10ada0851e796a4b}. 
\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ out}}  & {\em buf} & string buffer to write escaped characters to. \\
\hline
\mbox{\texttt{ in}}  & {\em bufsize} & sizeof(buf). \\
\hline
\mbox{\texttt{ in}}  & {\em str} & A string that may contain any characters. \\
\hline
\mbox{\texttt{ in}}  & {\em in\+\_\+len} & Pass -\/1 to print until nul char, or $>$= 0 to force a length. \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
The output buffer (buf). 
\end{DoxyReturn}


References \textbf{ \+\_\+osmo\+\_\+quote\+\_\+str\+\_\+buf()}, and \textbf{ osmo\+\_\+strbuf\+::buf}.

\mbox{\label{group__utils_gaad5dccba528c2ea4f9156dc61539ce79}} 
\index{General-\/purpose utility functions@{General-\/purpose utility functions}!osmo\_quote\_str\_buf3@{osmo\_quote\_str\_buf3}}
\index{osmo\_quote\_str\_buf3@{osmo\_quote\_str\_buf3}!General-\/purpose utility functions@{General-\/purpose utility functions}}
\doxysubsubsection{osmo\_quote\_str\_buf3()}
{\footnotesize\ttfamily int osmo\+\_\+quote\+\_\+str\+\_\+buf3 (\begin{DoxyParamCaption}\item[{char $\ast$}]{buf,  }\item[{size\+\_\+t}]{bufsize,  }\item[{const char $\ast$}]{str,  }\item[{int}]{in\+\_\+len }\end{DoxyParamCaption})}



Like \doxyref{osmo\+\_\+escape\+\_\+str\+\_\+buf3()}{p.}{group__utils_ga6b4866958eb385b561fc1fa91db242e7}, but returns double-\/quotes around a string, or \char`\"{}\+NULL\char`\"{} for a NULL string. 

This allows passing any char$\ast$ value and get its C representation as string. The function signature is suitable for \doxyref{OSMO\+\_\+\+STRBUF\+\_\+\+APPEND\+\_\+\+NOLEN()}{p.}{group__utils_gaba053478cf0abc6d10ada0851e796a4b}. 
\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ out}}  & {\em buf} & string buffer to write escaped characters to. \\
\hline
\mbox{\texttt{ in}}  & {\em bufsize} & sizeof(buf). \\
\hline
\mbox{\texttt{ in}}  & {\em str} & A string that may contain any characters. \\
\hline
\mbox{\texttt{ in}}  & {\em in\+\_\+len} & Pass -\/1 to print until nul char, or $>$= 0 to force a length. \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
Number of characters that would be written if bufsize were large enough excluding \textquotesingle{}\textbackslash{}0\textquotesingle{} (like snprintf()). 
\end{DoxyReturn}


References \textbf{ \+\_\+osmo\+\_\+quote\+\_\+str\+\_\+buf()}, and \textbf{ osmo\+\_\+strbuf\+::buf}.

\mbox{\label{group__utils_ga333f103771c3b46336103b57e2bc047c}} 
\index{General-\/purpose utility functions@{General-\/purpose utility functions}!osmo\_quote\_str\_c@{osmo\_quote\_str\_c}}
\index{osmo\_quote\_str\_c@{osmo\_quote\_str\_c}!General-\/purpose utility functions@{General-\/purpose utility functions}}
\doxysubsubsection{osmo\_quote\_str\_c()}
{\footnotesize\ttfamily char $\ast$ osmo\+\_\+quote\+\_\+str\+\_\+c (\begin{DoxyParamCaption}\item[{const void $\ast$}]{ctx,  }\item[{const char $\ast$}]{str,  }\item[{int}]{in\+\_\+len }\end{DoxyParamCaption})}



Like \doxyref{osmo\+\_\+quote\+\_\+str\+\_\+buf()}{p.}{group__utils_gad5c8e9dbe2d66556fde2a49418d2db89} but returns the result in a dynamically-\/allocated buffer. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em str} & A string that may contain any characters. \\
\hline
\mbox{\texttt{ in}}  & {\em in\+\_\+len} & Pass -\/1 to print until nul char, or $>$= 0 to force a length. \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
dynamically-\/allocated buffer containing a quoted and escaped representation. 
\end{DoxyReturn}


References \textbf{ \+\_\+osmo\+\_\+quote\+\_\+str\+\_\+buf()}, and \textbf{ OSMO\+\_\+\+NAME\+\_\+\+C\+\_\+\+IMPL}.

\mbox{\label{group__utils_gabac697c1ef493cb5691eb5f11c4af984}} 
\index{General-\/purpose utility functions@{General-\/purpose utility functions}!osmo\_separated\_identifiers\_valid@{osmo\_separated\_identifiers\_valid}}
\index{osmo\_separated\_identifiers\_valid@{osmo\_separated\_identifiers\_valid}!General-\/purpose utility functions@{General-\/purpose utility functions}}
\doxysubsubsection{osmo\_separated\_identifiers\_valid()}
{\footnotesize\ttfamily bool osmo\+\_\+separated\+\_\+identifiers\+\_\+valid (\begin{DoxyParamCaption}\item[{const char $\ast$}]{str,  }\item[{const char $\ast$}]{sep\+\_\+chars }\end{DoxyParamCaption})}



Determine if a given identifier is valid, i.\+e. 

doesn\textquotesingle{}t contain illegal chars 
\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em str} & String to validate \\
\hline
\mbox{\texttt{ in}}  & {\em sep\+\_\+chars} & Permitted separation characters between identifiers. \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
true in case {\itshape str} contains only valid identifiers and sep\+\_\+chars, false otherwise 
\end{DoxyReturn}


References \textbf{ len()}, and \textbf{ osmo\+\_\+identifier\+\_\+illegal\+\_\+chars}.



Referenced by \textbf{ osmo\+\_\+identifier\+\_\+valid()}.

\mbox{\label{group__utils_ga68ffd899763d4c8d24a8df1708b3fe9d}} 
\index{General-\/purpose utility functions@{General-\/purpose utility functions}!osmo\_set\_panic\_handler@{osmo\_set\_panic\_handler}}
\index{osmo\_set\_panic\_handler@{osmo\_set\_panic\_handler}!General-\/purpose utility functions@{General-\/purpose utility functions}}
\doxysubsubsection{osmo\_set\_panic\_handler()}
{\footnotesize\ttfamily void osmo\+\_\+set\+\_\+panic\+\_\+handler (\begin{DoxyParamCaption}\item[{\textbf{ osmo\+\_\+panic\+\_\+handler\+\_\+t}}]{h }\end{DoxyParamCaption})}



Set the panic handler. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em h} & New panic handler function\\
\hline
\end{DoxyParams}
This changes the panic handling function from the currently active function to a new call-\/back function supplied by the caller. 

References \textbf{ h}, and \textbf{ osmo\+\_\+panic\+\_\+handler}.

\mbox{\label{group__utils_gab595e5dac6365b78f85b07bb792da4de}} 
\index{General-\/purpose utility functions@{General-\/purpose utility functions}!osmo\_str2bcd@{osmo\_str2bcd}}
\index{osmo\_str2bcd@{osmo\_str2bcd}!General-\/purpose utility functions@{General-\/purpose utility functions}}
\doxysubsubsection{osmo\_str2bcd()}
{\footnotesize\ttfamily int osmo\+\_\+str2bcd (\begin{DoxyParamCaption}\item[{uint8\+\_\+t $\ast$}]{dst,  }\item[{size\+\_\+t}]{dst\+\_\+size,  }\item[{const char $\ast$}]{digits,  }\item[{int}]{start\+\_\+nibble,  }\item[{int}]{end\+\_\+nibble,  }\item[{bool}]{allow\+\_\+hex }\end{DoxyParamCaption})}



Convert string to BCD. 

The given nibble offsets are interpreted in BCD order, i.\+e. nibble 0 is bcd[0] \& 0x0f, nibble 1 is bcd[0] \& 0xf0, nibble 3 is bcd[1] \& 0x0f, etc.. 
\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ out}}  & {\em dst} & Output BCD buffer. \\
\hline
\mbox{\texttt{ in}}  & {\em dst\+\_\+size} & sizeof() the output string buffer. \\
\hline
\mbox{\texttt{ in}}  & {\em digits} & String containing decimal or hexadecimal digits in upper or lower case. \\
\hline
\mbox{\texttt{ in}}  & {\em start\+\_\+nibble} & Offset to start from, in nibbles, typically 1 to skip the first (MI type) nibble. \\
\hline
\mbox{\texttt{ in}}  & {\em end\+\_\+nibble} & Negative to write all digits found in str, followed by 0xf nibbles to fill any started octet. If $>$= 0, stop before this offset in nibbles, e.\+g. to get default behavior, pass start\+\_\+nibble + strlen(str) + ((start\+\_\+nibble + strlen(str)) \& 1? 1 \+: 0) + 1. \\
\hline
\mbox{\texttt{ in}}  & {\em allow\+\_\+hex} & If false, return error if there are hexadecimal digits (A-\/F). If true, write those to BCD. \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
The buffer size in octets that is used to place all bcd digits (including the skipped nibbles from \textquotesingle{}start\+\_\+nibble\textquotesingle{} and rounded up to full octets); -\/EINVAL on invalid digits; -\/ENOMEM if dst is NULL, if dst\+\_\+size is too small to contain all nibbles, or if start\+\_\+nibble is negative. 
\end{DoxyReturn}


References \textbf{ c}, and \textbf{ digits}.

\mbox{\label{group__utils_gab4197cdbb099e3677ebe9bd3538a6d85}} 
\index{General-\/purpose utility functions@{General-\/purpose utility functions}!osmo\_str2lower@{osmo\_str2lower}}
\index{osmo\_str2lower@{osmo\_str2lower}!General-\/purpose utility functions@{General-\/purpose utility functions}}
\doxysubsubsection{osmo\_str2lower()}
{\footnotesize\ttfamily void osmo\+\_\+str2lower (\begin{DoxyParamCaption}\item[{char $\ast$}]{out,  }\item[{const char $\ast$}]{in }\end{DoxyParamCaption})}

\mbox{\label{group__utils_gaeeb71577609999862abe6abde44153fc}} 
\index{General-\/purpose utility functions@{General-\/purpose utility functions}!osmo\_str2upper@{osmo\_str2upper}}
\index{osmo\_str2upper@{osmo\_str2upper}!General-\/purpose utility functions@{General-\/purpose utility functions}}
\doxysubsubsection{osmo\_str2upper()}
{\footnotesize\ttfamily void osmo\+\_\+str2upper (\begin{DoxyParamCaption}\item[{char $\ast$}]{out,  }\item[{const char $\ast$}]{in }\end{DoxyParamCaption})}

\mbox{\label{group__utils_ga4a6c1ebef675be298cab13bb226e5baa}} 
\index{General-\/purpose utility functions@{General-\/purpose utility functions}!osmo\_str\_startswith@{osmo\_str\_startswith}}
\index{osmo\_str\_startswith@{osmo\_str\_startswith}!General-\/purpose utility functions@{General-\/purpose utility functions}}
\doxysubsubsection{osmo\_str\_startswith()}
{\footnotesize\ttfamily bool osmo\+\_\+str\+\_\+startswith (\begin{DoxyParamCaption}\item[{const char $\ast$}]{str,  }\item[{const char $\ast$}]{startswith\+\_\+str }\end{DoxyParamCaption})}



Compare start of a string. 

This is an optimisation of \textquotesingle{}strstr(str, startswith\+\_\+str) == str\textquotesingle{} because it doesn\textquotesingle{}t search through the entire string. 
\begin{DoxyParams}{Parameters}
{\em str} & (Longer) string to compare. \\
\hline
{\em startswith\+\_\+str} & (Shorter) string to compare with the start of str. \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
true iff the first characters of str fully match startswith\+\_\+str or startswith\+\_\+str is empty. 
\end{DoxyReturn}
\mbox{\label{group__utils_ga4f16a335e3ab7c88595b23acfd7c6693}} 
\index{General-\/purpose utility functions@{General-\/purpose utility functions}!osmo\_str\_to\_int@{osmo\_str\_to\_int}}
\index{osmo\_str\_to\_int@{osmo\_str\_to\_int}!General-\/purpose utility functions@{General-\/purpose utility functions}}
\doxysubsubsection{osmo\_str\_to\_int()}
{\footnotesize\ttfamily int osmo\+\_\+str\+\_\+to\+\_\+int (\begin{DoxyParamCaption}\item[{int $\ast$}]{result,  }\item[{const char $\ast$}]{str,  }\item[{int}]{base,  }\item[{int}]{min\+\_\+val,  }\item[{int}]{max\+\_\+val }\end{DoxyParamCaption})}



Convert a string of a number to int, including all common strtoll() validity checks. 

Same as \doxyref{osmo\+\_\+str\+\_\+to\+\_\+int64()}{p.}{group__utils_ga503b0048081b15fd438bedce2173d5db} but using the plain int data type. 
\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ out}}  & {\em result} & Buffer for the resulting integer number, or NULL if the caller is only interested in the validation result (returned rc). \\
\hline
\mbox{\texttt{ in}}  & {\em str} & The string to convert. \\
\hline
\mbox{\texttt{ in}}  & {\em base} & The integer base, i.\+e. 10 for decimal numbers or 16 for hexadecimal, as in strtoll(). \\
\hline
\mbox{\texttt{ in}}  & {\em min\+\_\+val} & The smallest valid number expected in the string. \\
\hline
\mbox{\texttt{ in}}  & {\em max\+\_\+val} & The largest valid number expected in the string. \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
0 on success, -\/EOVERFLOW if the number in the string exceeds int range, -\/ENOTSUPP if the base is not supported, -\/ERANGE if the converted number exceeds the range [min\+\_\+val..max\+\_\+val] but is still within int range, -\/E2\+BIG if surplus characters follow after the number, -\/EINVAL if the string does not contain a number. In case of -\/ERANGE and -\/E2\+BIG, the converted number is still accurately returned in result. In case of -\/EOVERFLOW, the returned value is clamped to INT\+\_\+\+MIN..INT\+\_\+\+MAX. 
\end{DoxyReturn}


References \textbf{ osmo\+\_\+str\+\_\+to\+\_\+int64()}.

\mbox{\label{group__utils_ga503b0048081b15fd438bedce2173d5db}} 
\index{General-\/purpose utility functions@{General-\/purpose utility functions}!osmo\_str\_to\_int64@{osmo\_str\_to\_int64}}
\index{osmo\_str\_to\_int64@{osmo\_str\_to\_int64}!General-\/purpose utility functions@{General-\/purpose utility functions}}
\doxysubsubsection{osmo\_str\_to\_int64()}
{\footnotesize\ttfamily int osmo\+\_\+str\+\_\+to\+\_\+int64 (\begin{DoxyParamCaption}\item[{int64\+\_\+t $\ast$}]{result,  }\item[{const char $\ast$}]{str,  }\item[{int}]{base,  }\item[{int64\+\_\+t}]{min\+\_\+val,  }\item[{int64\+\_\+t}]{max\+\_\+val }\end{DoxyParamCaption})}



Convert a string of a number to int64\+\_\+t, including all common strtoll() validity checks. 

It\textquotesingle{}s not so trivial to call strtoll() and properly verify that the input string was indeed a valid number string. 
\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ out}}  & {\em result} & Buffer for the resulting integer number, or NULL if the caller is only interested in the validation result (returned rc). \\
\hline
\mbox{\texttt{ in}}  & {\em str} & The string to convert. \\
\hline
\mbox{\texttt{ in}}  & {\em base} & The integer base, i.\+e. 10 for decimal numbers or 16 for hexadecimal, as in strtoll(). \\
\hline
\mbox{\texttt{ in}}  & {\em min\+\_\+val} & The smallest valid number expected in the string. \\
\hline
\mbox{\texttt{ in}}  & {\em max\+\_\+val} & The largest valid number expected in the string. \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
0 on success, -\/EOVERFLOW if the number in the string exceeds int64\+\_\+t, -\/ENOTSUPP if the base is not supported, -\/ERANGE if the converted number exceeds the range [min\+\_\+val..max\+\_\+val] but is still within int64\+\_\+t range, -\/E2\+BIG if surplus characters follow after the number, -\/EINVAL if the string does not contain a number. In case of -\/ERANGE and -\/E2\+BIG, the converted number is still accurately returned in result. In case of -\/EOVERFLOW, the returned value is clamped to INT64\+\_\+\+MIN..INT64\+\_\+\+MAX. 
\end{DoxyReturn}


References \textbf{ ENOTSUP}.



Referenced by \textbf{ osmo\+\_\+str\+\_\+to\+\_\+int()}.

\mbox{\label{group__utils_gad40fab125b7c9f19ef1789f299a7617d}} 
\index{General-\/purpose utility functions@{General-\/purpose utility functions}!osmo\_str\_tolower@{osmo\_str\_tolower}}
\index{osmo\_str\_tolower@{osmo\_str\_tolower}!General-\/purpose utility functions@{General-\/purpose utility functions}}
\doxysubsubsection{osmo\_str\_tolower()}
{\footnotesize\ttfamily const char $\ast$ osmo\+\_\+str\+\_\+tolower (\begin{DoxyParamCaption}\item[{const char $\ast$}]{src }\end{DoxyParamCaption})}



Convert a string to lowercase, using a static buffer. 

The resulting string may be truncated if the internally used static buffer is shorter than src. The internal buffer is at least 128 bytes long, i.\+e. guaranteed to hold at least 127 characters and a terminating nul. The static buffer returned is shared with \doxyref{osmo\+\_\+str\+\_\+toupper()}{p.}{group__utils_ga02a608b84c87fa5cd65dcefc4c56b552}. See also \doxyref{osmo\+\_\+str\+\_\+tolower\+\_\+buf()}{p.}{group__utils_ga8912910863d88f52b9d62220ee66feed}. 
\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em src} & String to convert to lowercase. \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
Resulting lowercase string in a static buffer, always nul terminated. 
\end{DoxyReturn}


References \textbf{ capsbuf}, and \textbf{ osmo\+\_\+str\+\_\+tolower\+\_\+buf()}.

\mbox{\label{group__utils_ga8912910863d88f52b9d62220ee66feed}} 
\index{General-\/purpose utility functions@{General-\/purpose utility functions}!osmo\_str\_tolower\_buf@{osmo\_str\_tolower\_buf}}
\index{osmo\_str\_tolower\_buf@{osmo\_str\_tolower\_buf}!General-\/purpose utility functions@{General-\/purpose utility functions}}
\doxysubsubsection{osmo\_str\_tolower\_buf()}
{\footnotesize\ttfamily size\+\_\+t osmo\+\_\+str\+\_\+tolower\+\_\+buf (\begin{DoxyParamCaption}\item[{char $\ast$}]{dest,  }\item[{size\+\_\+t}]{dest\+\_\+len,  }\item[{const char $\ast$}]{src }\end{DoxyParamCaption})}



Convert a string to lowercase, while checking buffer size boundaries. 

The result written to {\itshape dest} is guaranteed to be nul terminated if {\itshape dest\+\_\+len} $>$ 0. If dest == src, the string is converted in-\/place, if necessary truncated at dest\+\_\+len -\/ 1 characters length as well as nul terminated. Note\+: similar \doxyref{osmo\+\_\+str2lower()}{p.}{group__utils_gab4197cdbb099e3677ebe9bd3538a6d85}, but safe to use for src strings of arbitrary length. 
\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ out}}  & {\em dest} & Target buffer to write lowercase string. \\
\hline
\mbox{\texttt{ in}}  & {\em dest\+\_\+len} & Maximum buffer size of dest (e.\+g. sizeof(dest)). \\
\hline
\mbox{\texttt{ in}}  & {\em src} & String to convert to lowercase. \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
Length of {\itshape src}, like \doxyref{osmo\+\_\+strlcpy()}{p.}{group__utils_ga2e880620479e4b79e28cc817cf451f9c}, but if {\itshape dest} == {\itshape src} at most {\itshape dest\+\_\+len} -\/ 1. 
\end{DoxyReturn}


References \textbf{ osmo\+\_\+strlcpy()}.



Referenced by \textbf{ osmo\+\_\+str\+\_\+tolower()}, and \textbf{ osmo\+\_\+str\+\_\+tolower\+\_\+c()}.

\mbox{\label{group__utils_ga20e4677fb667ab35e8cdc556f46f0043}} 
\index{General-\/purpose utility functions@{General-\/purpose utility functions}!osmo\_str\_tolower\_c@{osmo\_str\_tolower\_c}}
\index{osmo\_str\_tolower\_c@{osmo\_str\_tolower\_c}!General-\/purpose utility functions@{General-\/purpose utility functions}}
\doxysubsubsection{osmo\_str\_tolower\_c()}
{\footnotesize\ttfamily char $\ast$ osmo\+\_\+str\+\_\+tolower\+\_\+c (\begin{DoxyParamCaption}\item[{const void $\ast$}]{ctx,  }\item[{const char $\ast$}]{src }\end{DoxyParamCaption})}



Convert a string to lowercase, dynamically allocating the output from given talloc context See also \doxyref{osmo\+\_\+str\+\_\+tolower\+\_\+buf()}{p.}{group__utils_ga8912910863d88f52b9d62220ee66feed}. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em ctx} & talloc context from where to allocate the output string \\
\hline
\mbox{\texttt{ in}}  & {\em src} & String to convert to lowercase. \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
Resulting lowercase string in a dynamically allocated buffer, always nul terminated. 
\end{DoxyReturn}


References \textbf{ osmo\+\_\+strbuf\+::buf}, and \textbf{ osmo\+\_\+str\+\_\+tolower\+\_\+buf()}.

\mbox{\label{group__utils_ga02a608b84c87fa5cd65dcefc4c56b552}} 
\index{General-\/purpose utility functions@{General-\/purpose utility functions}!osmo\_str\_toupper@{osmo\_str\_toupper}}
\index{osmo\_str\_toupper@{osmo\_str\_toupper}!General-\/purpose utility functions@{General-\/purpose utility functions}}
\doxysubsubsection{osmo\_str\_toupper()}
{\footnotesize\ttfamily const char $\ast$ osmo\+\_\+str\+\_\+toupper (\begin{DoxyParamCaption}\item[{const char $\ast$}]{src }\end{DoxyParamCaption})}



Convert a string to uppercase, using a static buffer. 

The resulting string may be truncated if the internally used static buffer is shorter than src. The internal buffer is at least 128 bytes long, i.\+e. guaranteed to hold at least 127 characters and a terminating nul. The static buffer returned is shared with \doxyref{osmo\+\_\+str\+\_\+tolower()}{p.}{group__utils_gad40fab125b7c9f19ef1789f299a7617d}. See also \doxyref{osmo\+\_\+str\+\_\+toupper\+\_\+buf()}{p.}{group__utils_ga7134740c825b2f4b604e825aa6f06c58}. 
\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em src} & String to convert to uppercase. \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
Resulting uppercase string in a static buffer, always nul terminated. 
\end{DoxyReturn}


References \textbf{ capsbuf}, and \textbf{ osmo\+\_\+str\+\_\+toupper\+\_\+buf()}.

\mbox{\label{group__utils_ga7134740c825b2f4b604e825aa6f06c58}} 
\index{General-\/purpose utility functions@{General-\/purpose utility functions}!osmo\_str\_toupper\_buf@{osmo\_str\_toupper\_buf}}
\index{osmo\_str\_toupper\_buf@{osmo\_str\_toupper\_buf}!General-\/purpose utility functions@{General-\/purpose utility functions}}
\doxysubsubsection{osmo\_str\_toupper\_buf()}
{\footnotesize\ttfamily size\+\_\+t osmo\+\_\+str\+\_\+toupper\+\_\+buf (\begin{DoxyParamCaption}\item[{char $\ast$}]{dest,  }\item[{size\+\_\+t}]{dest\+\_\+len,  }\item[{const char $\ast$}]{src }\end{DoxyParamCaption})}



Convert a string to uppercase, while checking buffer size boundaries. 

The result written to {\itshape dest} is guaranteed to be nul terminated if {\itshape dest\+\_\+len} $>$ 0. If dest == src, the string is converted in-\/place, if necessary truncated at dest\+\_\+len -\/ 1 characters length as well as nul terminated. Note\+: similar \doxyref{osmo\+\_\+str2upper()}{p.}{group__utils_gaeeb71577609999862abe6abde44153fc}, but safe to use for src strings of arbitrary length. 
\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ out}}  & {\em dest} & Target buffer to write uppercase string. \\
\hline
\mbox{\texttt{ in}}  & {\em dest\+\_\+len} & Maximum buffer size of dest (e.\+g. sizeof(dest)). \\
\hline
\mbox{\texttt{ in}}  & {\em src} & String to convert to uppercase. \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
Length of {\itshape src}, like \doxyref{osmo\+\_\+strlcpy()}{p.}{group__utils_ga2e880620479e4b79e28cc817cf451f9c}, but if {\itshape dest} == {\itshape src} at most {\itshape dest\+\_\+len} -\/ 1. 
\end{DoxyReturn}


References \textbf{ osmo\+\_\+strlcpy()}.



Referenced by \textbf{ osmo\+\_\+str\+\_\+toupper()}, and \textbf{ osmo\+\_\+str\+\_\+toupper\+\_\+c()}.

\mbox{\label{group__utils_ga26450c1810f5f49e46865c9ea16737c0}} 
\index{General-\/purpose utility functions@{General-\/purpose utility functions}!osmo\_str\_toupper\_c@{osmo\_str\_toupper\_c}}
\index{osmo\_str\_toupper\_c@{osmo\_str\_toupper\_c}!General-\/purpose utility functions@{General-\/purpose utility functions}}
\doxysubsubsection{osmo\_str\_toupper\_c()}
{\footnotesize\ttfamily char $\ast$ osmo\+\_\+str\+\_\+toupper\+\_\+c (\begin{DoxyParamCaption}\item[{const void $\ast$}]{ctx,  }\item[{const char $\ast$}]{src }\end{DoxyParamCaption})}



Convert a string to uppercase, dynamically allocating the output from given talloc context See also \doxyref{osmo\+\_\+str\+\_\+tolower\+\_\+buf()}{p.}{group__utils_ga8912910863d88f52b9d62220ee66feed}. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em ctx} & talloc context from where to allocate the output string \\
\hline
\mbox{\texttt{ in}}  & {\em src} & String to convert to uppercase. \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
Resulting uppercase string in a dynamically allocated buffer, always nul terminated. 
\end{DoxyReturn}


References \textbf{ osmo\+\_\+strbuf\+::buf}, and \textbf{ osmo\+\_\+str\+\_\+toupper\+\_\+buf()}.

\mbox{\label{group__utils_ga1b89d94b3562b0b3261aff7c1ce4c395}} 
\index{General-\/purpose utility functions@{General-\/purpose utility functions}!osmo\_strbuf\_added\_tail@{osmo\_strbuf\_added\_tail}}
\index{osmo\_strbuf\_added\_tail@{osmo\_strbuf\_added\_tail}!General-\/purpose utility functions@{General-\/purpose utility functions}}
\doxysubsubsection{osmo\_strbuf\_added\_tail()}
{\footnotesize\ttfamily void osmo\+\_\+strbuf\+\_\+added\+\_\+tail (\begin{DoxyParamCaption}\item[{struct \textbf{ osmo\+\_\+strbuf} $\ast$}]{sb,  }\item[{size\+\_\+t}]{n\+\_\+chars }\end{DoxyParamCaption})}



Let \doxyref{osmo\+\_\+strbuf}{p.}{structosmo__strbuf} know that n\+\_\+chars characters (excluding nul) were written to the end of the buffer. 

If sb is nonempty, the n\+\_\+chars are assumed to have been written to sb-\/$>$pos. If sb is still empty and pos == NULL, the n\+\_\+chars are assumed to have been written to the start of the buffer. Advance sb-\/$>$pos and sb-\/$>$chars\+\_\+needed by at most n\+\_\+chars, or up to sb-\/$>$len -\/ 1. Ensure nul termination. 

References \textbf{ osmo\+\_\+strbuf\+::buf}, \textbf{ osmo\+\_\+strbuf\+::chars\+\_\+needed}, \textbf{ osmo\+\_\+strbuf\+::len}, \textbf{ OSMO\+\_\+\+MIN}, \textbf{ OSMO\+\_\+\+STRBUF\+\_\+\+REMAIN}, and \textbf{ osmo\+\_\+strbuf\+::pos}.

\mbox{\label{group__utils_ga2f3bd04cb9d1371b4e1b3ff0029f7238}} 
\index{General-\/purpose utility functions@{General-\/purpose utility functions}!osmo\_strbuf\_drop\_tail@{osmo\_strbuf\_drop\_tail}}
\index{osmo\_strbuf\_drop\_tail@{osmo\_strbuf\_drop\_tail}!General-\/purpose utility functions@{General-\/purpose utility functions}}
\doxysubsubsection{osmo\_strbuf\_drop\_tail()}
{\footnotesize\ttfamily void osmo\+\_\+strbuf\+\_\+drop\+\_\+tail (\begin{DoxyParamCaption}\item[{struct \textbf{ osmo\+\_\+strbuf} $\ast$}]{sb,  }\item[{size\+\_\+t}]{n\+\_\+chars }\end{DoxyParamCaption})}



Remove up to N chars from the end of an \doxyref{osmo\+\_\+strbuf}{p.}{structosmo__strbuf}. 

$\vert$--char-\/count---$\vert$ -\/ -\/ chars\+\_\+needed -\/ -\/ $\vert$ $\vert$$<$-\/-\/-\/-\/-\/-\/---drop-\/-\/-\/-\/-\/-\/-\/---$\vert$ 

References \textbf{ osmo\+\_\+strbuf\+::buf}, \textbf{ osmo\+\_\+strbuf\+::chars\+\_\+needed}, \textbf{ OSMO\+\_\+\+MIN}, \textbf{ OSMO\+\_\+\+STRBUF\+\_\+\+CHAR\+\_\+\+COUNT}, and \textbf{ osmo\+\_\+strbuf\+::pos}.

\mbox{\label{group__utils_ga2e880620479e4b79e28cc817cf451f9c}} 
\index{General-\/purpose utility functions@{General-\/purpose utility functions}!osmo\_strlcpy@{osmo\_strlcpy}}
\index{osmo\_strlcpy@{osmo\_strlcpy}!General-\/purpose utility functions@{General-\/purpose utility functions}}
\doxysubsubsection{osmo\_strlcpy()}
{\footnotesize\ttfamily size\+\_\+t osmo\+\_\+strlcpy (\begin{DoxyParamCaption}\item[{char $\ast$}]{dst,  }\item[{const char $\ast$}]{src,  }\item[{size\+\_\+t}]{siz }\end{DoxyParamCaption})}



Copy a C-\/string into a sized buffer. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em src} & source string \\
\hline
\mbox{\texttt{ out}}  & {\em dst} & destination string \\
\hline
\mbox{\texttt{ in}}  & {\em siz} & size of the {\itshape dst} buffer \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
length of {\itshape src} 
\end{DoxyReturn}
Copy at most {\itshape siz} bytes from {\itshape src} to {\itshape dst}, ensuring that the result is NUL terminated. The NUL character is included in {\itshape siz}, i.\+e. passing the actual sizeof($\ast$dst) is correct.

Note, a similar function that also limits the input buffer size is \doxyref{osmo\+\_\+print\+\_\+n()}{p.}{group__utils_ga412b892efd1aa17d024863cd103f3fbc}. 

References \textbf{ len()}, and \textbf{ OSMO\+\_\+\+MIN}.



Referenced by \textbf{ osmo\+\_\+float\+\_\+str\+\_\+to\+\_\+int()}, \textbf{ osmo\+\_\+str\+\_\+tolower\+\_\+buf()}, and \textbf{ osmo\+\_\+str\+\_\+toupper\+\_\+buf()}.

\mbox{\label{group__utils_ga3a809d9d2539c0bb3683ae4f0d16decc}} 
\index{General-\/purpose utility functions@{General-\/purpose utility functions}!osmo\_strnchr@{osmo\_strnchr}}
\index{osmo\_strnchr@{osmo\_strnchr}!General-\/purpose utility functions@{General-\/purpose utility functions}}
\doxysubsubsection{osmo\_strnchr()}
{\footnotesize\ttfamily const char $\ast$ osmo\+\_\+strnchr (\begin{DoxyParamCaption}\item[{const char $\ast$}]{str,  }\item[{size\+\_\+t}]{str\+\_\+size,  }\item[{char}]{c }\end{DoxyParamCaption})}



Find first occurence of a char in a size limited string. 

Like strchr() but with a buffer size limit. 
\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em str} & String buffer to examine. \\
\hline
\mbox{\texttt{ in}}  & {\em str\+\_\+size} & sizeof(str). \\
\hline
\mbox{\texttt{ in}}  & {\em c} & Character to look for. \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
Pointer to the matched char, or NULL if not found. 
\end{DoxyReturn}


References \textbf{ c}.

\mbox{\label{group__utils_ga3d8e138301a2fc21779b7259831a677c}} 
\index{General-\/purpose utility functions@{General-\/purpose utility functions}!osmo\_strrb\_add@{osmo\_strrb\_add}}
\index{osmo\_strrb\_add@{osmo\_strrb\_add}!General-\/purpose utility functions@{General-\/purpose utility functions}}
\doxysubsubsection{osmo\_strrb\_add()}
{\footnotesize\ttfamily int osmo\+\_\+strrb\+\_\+add (\begin{DoxyParamCaption}\item[{struct \textbf{ osmo\+\_\+strrb} $\ast$}]{rb,  }\item[{const char $\ast$}]{data }\end{DoxyParamCaption})}



Add a string to the \doxyref{osmo\+\_\+strrb}{p.}{structosmo__strrb}. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em rb} & The \doxyref{osmo\+\_\+strrb}{p.}{structosmo__strrb} to add to. \\
\hline
\mbox{\texttt{ in}}  & {\em data} & The string to add.\\
\hline
\end{DoxyParams}
Add a message to the \doxyref{osmo\+\_\+strrb}{p.}{structosmo__strrb}. Older messages will be overwritten as necessary. \begin{DoxyReturn}{Returns}
0 normally, 1 as a warning (ie, if data was truncated). 
\end{DoxyReturn}


References \textbf{ osmo\+\_\+strrb\+::buffer}, \textbf{ data}, \textbf{ osmo\+\_\+strrb\+::end}, \textbf{ len()}, \textbf{ RB\+\_\+\+MAX\+\_\+\+MESSAGE\+\_\+\+SIZE}, \textbf{ osmo\+\_\+strrb\+::size}, and \textbf{ osmo\+\_\+strrb\+::start}.



Referenced by \textbf{ \+\_\+rb\+\_\+output()}.

\mbox{\label{group__utils_gaaab7bfea64d0b1b7e86dbd717d253a30}} 
\index{General-\/purpose utility functions@{General-\/purpose utility functions}!osmo\_strrb\_create@{osmo\_strrb\_create}}
\index{osmo\_strrb\_create@{osmo\_strrb\_create}!General-\/purpose utility functions@{General-\/purpose utility functions}}
\doxysubsubsection{osmo\_strrb\_create()}
{\footnotesize\ttfamily struct \textbf{ osmo\+\_\+strrb} $\ast$ osmo\+\_\+strrb\+\_\+create (\begin{DoxyParamCaption}\item[{void $\ast$}]{talloc\+\_\+ctx,  }\item[{size\+\_\+t}]{rb\+\_\+size }\end{DoxyParamCaption})}



Create an empty, initialized \doxyref{osmo\+\_\+strrb}{p.}{structosmo__strrb}. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em ctx} & The talloc memory context which should own this. \\
\hline
\mbox{\texttt{ in}}  & {\em rb\+\_\+size} & The number of message slots the \doxyref{osmo\+\_\+strrb}{p.}{structosmo__strrb} can hold. \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
A struct osmo\+\_\+strrb$\ast$ on success, NULL in case of error.
\end{DoxyReturn}
This function creates and initializes a ringbuffer. Note that the ringbuffer stores at most rb\+\_\+size -\/ 1 messages. 

References \textbf{ osmo\+\_\+strrb\+::buffer}, \textbf{ RB\+\_\+\+MAX\+\_\+\+MESSAGE\+\_\+\+SIZE}, and \textbf{ osmo\+\_\+strrb\+::size}.



Referenced by \textbf{ log\+\_\+target\+\_\+create\+\_\+rb()}.

\mbox{\label{group__utils_gac730d01ff38c9eb9e9f10ce1f12cf3f0}} 
\index{General-\/purpose utility functions@{General-\/purpose utility functions}!osmo\_strrb\_elements@{osmo\_strrb\_elements}}
\index{osmo\_strrb\_elements@{osmo\_strrb\_elements}!General-\/purpose utility functions@{General-\/purpose utility functions}}
\doxysubsubsection{osmo\_strrb\_elements()}
{\footnotesize\ttfamily size\+\_\+t osmo\+\_\+strrb\+\_\+elements (\begin{DoxyParamCaption}\item[{const struct \textbf{ osmo\+\_\+strrb} $\ast$}]{rb }\end{DoxyParamCaption})}



Count the number of log messages in an \doxyref{osmo\+\_\+strrb}{p.}{structosmo__strrb}. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em rb} & The \doxyref{osmo\+\_\+strrb}{p.}{structosmo__strrb} to count the elements of.\\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
The number of log messages in the \doxyref{osmo\+\_\+strrb}{p.}{structosmo__strrb}. 
\end{DoxyReturn}


References \textbf{ osmo\+\_\+strrb\+::end}, \textbf{ osmo\+\_\+strrb\+::size}, and \textbf{ osmo\+\_\+strrb\+::start}.



Referenced by \textbf{ log\+\_\+target\+\_\+rb\+\_\+used\+\_\+size()}.

\mbox{\label{group__utils_ga284dcee685ff37d0138d1f739ff24d20}} 
\index{General-\/purpose utility functions@{General-\/purpose utility functions}!osmo\_strrb\_get\_nth@{osmo\_strrb\_get\_nth}}
\index{osmo\_strrb\_get\_nth@{osmo\_strrb\_get\_nth}!General-\/purpose utility functions@{General-\/purpose utility functions}}
\doxysubsubsection{osmo\_strrb\_get\_nth()}
{\footnotesize\ttfamily const char $\ast$ osmo\+\_\+strrb\+\_\+get\+\_\+nth (\begin{DoxyParamCaption}\item[{const struct \textbf{ osmo\+\_\+strrb} $\ast$}]{rb,  }\item[{unsigned int}]{string\+\_\+index }\end{DoxyParamCaption})}



Return a pointer to the Nth string in the \doxyref{osmo\+\_\+strrb}{p.}{structosmo__strrb}. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em rb} & The \doxyref{osmo\+\_\+strrb}{p.}{structosmo__strrb} to search. \\
\hline
\mbox{\texttt{ in}}  & {\em string\+\_\+index} & The index sought (N), zero-\/indexed.\\
\hline
\end{DoxyParams}
Return a pointer to the Nth string in the \doxyref{osmo\+\_\+strrb}{p.}{structosmo__strrb}. Return NULL if there is no Nth string. Note that N is zero-\/indexed. \begin{DoxyReturn}{Returns}
A pointer to the target string on success, NULL in case of error. 
\end{DoxyReturn}


References \textbf{ \+\_\+osmo\+\_\+strrb\+\_\+is\+\_\+bufindex\+\_\+valid()}, \textbf{ osmo\+\_\+strrb\+::buffer}, \textbf{ osmo\+\_\+strrb\+::end}, \textbf{ osmo\+\_\+strrb\+::size}, and \textbf{ osmo\+\_\+strrb\+::start}.



Referenced by \textbf{ log\+\_\+target\+\_\+rb\+\_\+get()}.

\mbox{\label{group__utils_gaa8d2f58d4f27e99836d85b5e5c568136}} 
\index{General-\/purpose utility functions@{General-\/purpose utility functions}!osmo\_strrb\_is\_empty@{osmo\_strrb\_is\_empty}}
\index{osmo\_strrb\_is\_empty@{osmo\_strrb\_is\_empty}!General-\/purpose utility functions@{General-\/purpose utility functions}}
\doxysubsubsection{osmo\_strrb\_is\_empty()}
{\footnotesize\ttfamily bool osmo\+\_\+strrb\+\_\+is\+\_\+empty (\begin{DoxyParamCaption}\item[{const struct \textbf{ osmo\+\_\+strrb} $\ast$}]{rb }\end{DoxyParamCaption})}



Check if an \doxyref{osmo\+\_\+strrb}{p.}{structosmo__strrb} is empty. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em rb} & The \doxyref{osmo\+\_\+strrb}{p.}{structosmo__strrb} to check. \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
True if the \doxyref{osmo\+\_\+strrb}{p.}{structosmo__strrb} is empty, false otherwise. 
\end{DoxyReturn}


References \textbf{ osmo\+\_\+strrb\+::end}, and \textbf{ osmo\+\_\+strrb\+::start}.



Referenced by \textbf{ \+\_\+osmo\+\_\+strrb\+\_\+is\+\_\+bufindex\+\_\+valid()}.

\mbox{\label{group__utils_ga44e4192da7885c2f45e8d46cb9a6c0c1}} 
\index{General-\/purpose utility functions@{General-\/purpose utility functions}!osmo\_talloc\_replace\_string@{osmo\_talloc\_replace\_string}}
\index{osmo\_talloc\_replace\_string@{osmo\_talloc\_replace\_string}!General-\/purpose utility functions@{General-\/purpose utility functions}}
\doxysubsubsection{osmo\_talloc\_replace\_string()}
{\footnotesize\ttfamily static void osmo\+\_\+talloc\+\_\+replace\+\_\+string (\begin{DoxyParamCaption}\item[{void $\ast$}]{ctx,  }\item[{char $\ast$$\ast$}]{dst,  }\item[{const char $\ast$}]{newstr }\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [inline]}, {\ttfamily [static]}}



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


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em ctx} & Talloc context to use for allocation \\
\hline
\mbox{\texttt{ out}}  & {\em dst} & pointer to string, will be updated with ptr to new string \\
\hline
\mbox{\texttt{ in}}  & {\em newstr} & String that will be copied to newly allocated string \\
\hline
\end{DoxyParams}


Referenced by \textbf{ osmo\+\_\+iofd\+\_\+set\+\_\+name()}, \textbf{ osmo\+\_\+netdev\+\_\+register()}, \textbf{ osmo\+\_\+netdev\+\_\+set\+\_\+netns\+\_\+name()}, \textbf{ osmo\+\_\+soft\+\_\+uart\+\_\+set\+\_\+name()}, \textbf{ osmo\+\_\+stat\+\_\+item\+\_\+group\+\_\+set\+\_\+name()}, \textbf{ osmo\+\_\+tundev\+\_\+set\+\_\+dev\+\_\+name()}, \textbf{ osmo\+\_\+tundev\+\_\+set\+\_\+netns\+\_\+name()}, \textbf{ rate\+\_\+ctr\+\_\+group\+\_\+set\+\_\+name()}, and \textbf{ tundev\+\_\+dev\+\_\+name\+\_\+chg\+\_\+cb()}.

\mbox{\label{group__utils_ga3c2b44ccd3575ebf985c63fab6158cd6}} 
\index{General-\/purpose utility functions@{General-\/purpose utility functions}!osmo\_talloc\_replace\_string\_fmt@{osmo\_talloc\_replace\_string\_fmt}}
\index{osmo\_talloc\_replace\_string\_fmt@{osmo\_talloc\_replace\_string\_fmt}!General-\/purpose utility functions@{General-\/purpose utility functions}}
\doxysubsubsection{osmo\_talloc\_replace\_string\_fmt()}
{\footnotesize\ttfamily void osmo\+\_\+talloc\+\_\+replace\+\_\+string\+\_\+fmt (\begin{DoxyParamCaption}\item[{void $\ast$}]{ctx,  }\item[{char $\ast$$\ast$}]{dst,  }\item[{const char $\ast$}]{fmt,  }\item[{}]{... }\end{DoxyParamCaption})}



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

This is a format string capable equivalent of \doxyref{osmo\+\_\+talloc\+\_\+replace\+\_\+string()}{p.}{group__utils_ga44e4192da7885c2f45e8d46cb9a6c0c1}. 
\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em ctx} & Talloc context to use for allocation. \\
\hline
\mbox{\texttt{ out}}  & {\em dst} & Pointer to string, will be updated with ptr to new string. \\
\hline
\mbox{\texttt{ in}}  & {\em fmt} & Format string that will be copied to newly allocated string. \\
\hline
\end{DoxyParams}


References \textbf{ name}.

\mbox{\label{group__utils_ga5df14e6f8be6d0581b9ef9138b8cc85f}} 
\index{General-\/purpose utility functions@{General-\/purpose utility functions}!osmo\_ubit\_dump@{osmo\_ubit\_dump}}
\index{osmo\_ubit\_dump@{osmo\_ubit\_dump}!General-\/purpose utility functions@{General-\/purpose utility functions}}
\doxysubsubsection{osmo\_ubit\_dump()}
{\footnotesize\ttfamily char $\ast$ osmo\+\_\+ubit\+\_\+dump (\begin{DoxyParamCaption}\item[{const uint8\+\_\+t $\ast$}]{bits,  }\item[{unsigned int}]{len }\end{DoxyParamCaption})}



Convert a sequence of unpacked bits to ASCII string, in static buffer. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ in}}  & {\em bits} & A sequence of unpacked bits \\
\hline
\mbox{\texttt{ in}}  & {\em len} & Length of bits \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
string representation in static buffer. 
\end{DoxyReturn}


References \textbf{ hexd\+\_\+buff}, \textbf{ len()}, and \textbf{ osmo\+\_\+ubit\+\_\+dump\+\_\+buf()}.

\mbox{\label{group__utils_ga48a25995cfdcb169407c0285e318b5ab}} 
\index{General-\/purpose utility functions@{General-\/purpose utility functions}!osmo\_ubit\_dump\_buf@{osmo\_ubit\_dump\_buf}}
\index{osmo\_ubit\_dump\_buf@{osmo\_ubit\_dump\_buf}!General-\/purpose utility functions@{General-\/purpose utility functions}}
\doxysubsubsection{osmo\_ubit\_dump\_buf()}
{\footnotesize\ttfamily char $\ast$ osmo\+\_\+ubit\+\_\+dump\+\_\+buf (\begin{DoxyParamCaption}\item[{char $\ast$}]{buf,  }\item[{size\+\_\+t}]{buf\+\_\+len,  }\item[{const uint8\+\_\+t $\ast$}]{bits,  }\item[{unsigned int}]{len }\end{DoxyParamCaption})}



Convert a sequence of unpacked bits to ASCII string, in user-\/supplied buffer. 


\begin{DoxyParams}[1]{Parameters}
\mbox{\texttt{ out}}  & {\em buf} & caller-\/provided output string buffer \\
\hline
\mbox{\texttt{ out}}  & {\em buf\+\_\+len} & size of buf in bytes \\
\hline
\mbox{\texttt{ in}}  & {\em bits} & A sequence of unpacked bits \\
\hline
\mbox{\texttt{ in}}  & {\em len} & Length of bits \\
\hline
\end{DoxyParams}
\begin{DoxyReturn}{Returns}
The output buffer (buf). 
\end{DoxyReturn}


References \textbf{ len()}.



Referenced by \textbf{ osmo\+\_\+ubit\+\_\+dump()}.



\doxysubsection{Variable Documentation}
\mbox{\label{group__utils_gac42d57a93bf148fdb275fde47abca8df}} 
\index{General-\/purpose utility functions@{General-\/purpose utility functions}!bounds@{bounds}}
\index{bounds@{bounds}!General-\/purpose utility functions@{General-\/purpose utility functions}}
\doxysubsubsection{bounds}
{\footnotesize\ttfamily void to properly check target \textbf{ memory} bounds}

\mbox{\label{group__utils_gad408aac8db7d8f74ea76b6012d9c3724}} 
\index{General-\/purpose utility functions@{General-\/purpose utility functions}!capsbuf@{capsbuf}}
\index{capsbuf@{capsbuf}!General-\/purpose utility functions@{General-\/purpose utility functions}}
\doxysubsubsection{capsbuf}
{\footnotesize\ttfamily \+\_\+\+\_\+thread char capsbuf[128]\hspace{0.3cm}{\ttfamily [static]}}



Referenced by \textbf{ osmo\+\_\+str\+\_\+tolower()}, and \textbf{ osmo\+\_\+str\+\_\+toupper()}.

\mbox{\label{group__utils_ga88e2bcf3138cbb40f80836c959476257}} 
\index{General-\/purpose utility functions@{General-\/purpose utility functions}!hex\_chars@{hex\_chars}}
\index{hex\_chars@{hex\_chars}!General-\/purpose utility functions@{General-\/purpose utility functions}}
\doxysubsubsection{hex\_chars}
{\footnotesize\ttfamily const char hex\+\_\+chars[$\,$] = \char`\"{}0123456789abcdef\char`\"{}\hspace{0.3cm}{\ttfamily [static]}}



Referenced by \textbf{ osmo\+\_\+hexdump\+\_\+buf()}.

\mbox{\label{group__utils_gae2778983d0cf60080bb3232e764704a2}} 
\index{General-\/purpose utility functions@{General-\/purpose utility functions}!hexd\_buff@{hexd\_buff}}
\index{hexd\_buff@{hexd\_buff}!General-\/purpose utility functions@{General-\/purpose utility functions}}
\doxysubsubsection{hexd\_buff}
{\footnotesize\ttfamily \+\_\+\+\_\+thread char hexd\+\_\+buff[4096]\hspace{0.3cm}{\ttfamily [static]}}



Referenced by \textbf{ osmo\+\_\+hexdump()}, \textbf{ osmo\+\_\+hexdump\+\_\+c()}, \textbf{ osmo\+\_\+hexdump\+\_\+nospc()}, \textbf{ osmo\+\_\+hexdump\+\_\+nospc\+\_\+c()}, and \textbf{ osmo\+\_\+ubit\+\_\+dump()}.

\mbox{\label{group__utils_ga42e7a63c73abd5c30aee0ee87ed6e11a}} 
\index{General-\/purpose utility functions@{General-\/purpose utility functions}!namebuf@{namebuf}}
\index{namebuf@{namebuf}!General-\/purpose utility functions@{General-\/purpose utility functions}}
\doxysubsubsection{namebuf}
{\footnotesize\ttfamily \+\_\+\+\_\+thread char namebuf[255]\hspace{0.3cm}{\ttfamily [static]}}



Referenced by \textbf{ get\+\_\+value\+\_\+string()}, \textbf{ osmo\+\_\+escape\+\_\+str()}, and \textbf{ osmo\+\_\+quote\+\_\+str()}.

\mbox{\label{group__utils_ga46a5e6d68d174e66705e6a5ab3068166}} 
\index{General-\/purpose utility functions@{General-\/purpose utility functions}!osmo\_identifier\_illegal\_chars@{osmo\_identifier\_illegal\_chars}}
\index{osmo\_identifier\_illegal\_chars@{osmo\_identifier\_illegal\_chars}!General-\/purpose utility functions@{General-\/purpose utility functions}}
\doxysubsubsection{osmo\_identifier\_illegal\_chars}
{\footnotesize\ttfamily const char osmo\+\_\+identifier\+\_\+illegal\+\_\+chars[$\,$] = \char`\"{}., \{\}[$\,$]()$<$$>$$\vert$$\sim$\textbackslash{}\textbackslash{}$^\wedge$\`{}\textquotesingle{}\textbackslash{}\char`\"{}?=;/+$\ast$\&\%\$\#!\char`\"{}\hspace{0.3cm}{\ttfamily [static]}}



Referenced by \textbf{ osmo\+\_\+identifier\+\_\+sanitize\+\_\+buf()}, and \textbf{ osmo\+\_\+separated\+\_\+identifiers\+\_\+valid()}.

\mbox{\label{group__utils_gad9bb92023569bababaef4bbf1ed9f99b}} 
\index{General-\/purpose utility functions@{General-\/purpose utility functions}!osmo\_panic\_handler@{osmo\_panic\_handler}}
\index{osmo\_panic\_handler@{osmo\_panic\_handler}!General-\/purpose utility functions@{General-\/purpose utility functions}}
\doxysubsubsection{osmo\_panic\_handler}
{\footnotesize\ttfamily \textbf{ osmo\+\_\+panic\+\_\+handler\+\_\+t} osmo\+\_\+panic\+\_\+handler = (void$\ast$)0\hspace{0.3cm}{\ttfamily [static]}}



Referenced by \textbf{ osmo\+\_\+panic()}, and \textbf{ osmo\+\_\+set\+\_\+panic\+\_\+handler()}.

