\doxysection{include/osmocom/core/utils.h File Reference}
\label{utils_8h}\index{include/osmocom/core/utils.h@{include/osmocom/core/utils.h}}
{\ttfamily \#include $<$stdbool.\+h$>$}\newline
{\ttfamily \#include $<$stdint.\+h$>$}\newline
{\ttfamily \#include $<$stdio.\+h$>$}\newline
{\ttfamily \#include $<$string.\+h$>$}\newline
{\ttfamily \#include $<$osmocom/core/backtrace.\+h$>$}\newline
{\ttfamily \#include $<$osmocom/core/talloc.\+h$>$}\newline
{\ttfamily \#include $<$osmocom/core/panic.\+h$>$}\newline
{\ttfamily \#include $<$osmocom/core/defs.\+h$>$}\newline
\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{ 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*{Functions}
\begin{DoxyCompactItemize}
\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}\end{DoxyCompactItemize}
\doxysubsection*{Variables}
\begin{DoxyCompactItemize}
\item 
void to properly check target \textbf{ memory} \textbf{ bounds}
\end{DoxyCompactItemize}
