libosmocore 1.13.1.1-afb4 Osmocom core library

utils.h
Go to the documentation of this file.
1#pragma once
2
3#include <stdbool.h>
4#include <stdint.h>
5#include <stdio.h>
6#include <string.h>
7
8#include <osmocom/core/backtrace.h>
9#include <osmocom/core/talloc.h>
10#include <osmocom/core/panic.h>
11#include <osmocom/core/defs.h>
12
18#ifndef ARRAY_SIZE
19#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
20#endif
22#define OSMO_MAX(a, b) ((a) >= (b) ? (a) : (b))
24#define OSMO_MIN(a, b) ((a) >= (b) ? (b) : (a))
26#define OSMO_CMP(a, b) ((a) < (b)? -1 : ((a) > (b)? 1 : 0))
30#define OSMO_STRINGIFY(x) #x
32#define OSMO_STRINGIFY_VAL(x) OSMO_STRINGIFY(x)
34#define OSMO_VALUE_STRING(x) { x, #x }
36#define OSMO_BYTES_FOR_BITS(BITS) (((BITS) + 7) / 8)
37
39#define OSMO_STRLCPY_ARRAY(array, src) osmo_strlcpy(array, src, sizeof(array))
40
42#if defined(__GNUC__)
43#define OSMO_LIKELY(exp) __builtin_expect(!!(exp), 1)
44#define OSMO_UNLIKELY(exp) __builtin_expect(!!(exp), 0)
45#else
46#define OSMO_LIKELY(exp) exp
47#define OSMO_UNLIKELY(exp) exp
48#endif
49
51 struct value_string {
52 uint32_t value;
53 const char *str;
54};
55
56 const char *get_value_string(const struct value_string *vs, uint32_t val);
57 const char *get_value_string_or_null(const struct value_string *vs,
58 uint32_t val);
59
60 int get_string_value(const struct value_string *vs, const char *str);
61
62 char osmo_bcd2char(uint8_t bcd);
63/* only works for numbers in ASCII */
64uint8_t osmo_char2bcd(char c);
65
66 int osmo_bcd2str(char *dst, size_t dst_size, const uint8_t *bcd, int start_nibble, int end_nibble, bool allow_hex);
67 int osmo_str2bcd(uint8_t *dst, size_t dst_size, const char *digits, int start_nibble, int end_nibble, bool allow_hex);
68
69 int osmo_hexparse(const char *str, uint8_t *b, unsigned int max_len);
70
71 char *osmo_ubit_dump_buf(char *buf, size_t buf_len, const uint8_t *bits, unsigned int len);
72 char *osmo_ubit_dump(const uint8_t *bits, unsigned int len);
73 char *osmo_hexdump(const unsigned char *buf, int len);
74 char *osmo_hexdump_c(const void *ctx, const unsigned char *buf, int len);
75 char *osmo_hexdump_nospc(const unsigned char *buf, int len);
76 char *osmo_hexdump_nospc_c(const void *ctx, const unsigned char *buf, int len);
77 const char *osmo_hexdump_buf(char *out_buf, size_t out_buf_size, const unsigned char *buf, int len, const char *delim,
78 bool delim_after_last);
79
80 char *osmo_osmo_hexdump_nospc(const unsigned char *buf, int len) __attribute__((__deprecated__));
81
82#define osmo_static_assert(exp, name) typedef int dummy##name [(exp) ? 1 : -1] __attribute__((__unused__));
83
84 void osmo_str2lower(char *out, const char *in)
85 OSMO_DEPRECATED("Use osmo_str_tolower() or osmo_str_tolower_buf() instead,"
86 " to properly check target memory bounds");
87 void osmo_str2upper(char *out, const char *in)
88 OSMO_DEPRECATED("Use osmo_str_toupper() or osmo_str_toupper_buf() instead,"
89 " to properly check target memory bounds");
90
91 size_t osmo_str_tolower_buf(char *dest, size_t dest_len, const char *src);
92 const char *osmo_str_tolower(const char *src);
93 char *osmo_str_tolower_c(const void *ctx, const char *src);
94
95 size_t osmo_str_toupper_buf(char *dest, size_t dest_len, const char *src);
96 const char *osmo_str_toupper(const char *src);
97 char *osmo_str_toupper_c(const void *ctx, const char *src);
98
99#define OSMO_SNPRINTF_RET(ret, rem, offset, len) \
100 do { \
101 len += ret; \
102 if (ret > rem) \
103 ret = rem; \
104 offset += ret; \
105 rem -= ret; \
106} while (0)
107
113#define OSMO_ASSERT(exp) \
114 do { \
115 if (OSMO_UNLIKELY(!(exp))) { \
116 osmo_panic("Assert failed %s %s:%d\n", #exp, __FILE__, __LINE__); \
117 } \
118} while (0); /* some code invokes OSMO_ASSERT() without the semicolon */
119
124 static inline void osmo_talloc_replace_string(void *ctx, char **dst, const char *newstr)
125{
126 if (*dst)
127 talloc_free(*dst);
128 *dst = talloc_strdup(ctx, newstr);
129}
130
131 void osmo_talloc_replace_string_fmt(void *ctx, char **dst, const char *fmt, ...);
132
143#define osmo_talloc_asprintf(ctx, dest, fmt, args ...) \
144 do { \
145 if (!dest) \
146 dest = talloc_asprintf(ctx, fmt, ## args); \
147 else \
148 dest = talloc_asprintf_append((char*)dest, fmt, ## args); \
149 } while (0)
150
151 int osmo_constant_time_cmp(const uint8_t *exp, const uint8_t *rel, const int count);
152uint64_t osmo_decode_big_endian(const uint8_t *data, size_t data_len);
153uint8_t *osmo_encode_big_endian(uint64_t value, size_t data_len);
154
155 size_t osmo_strlcpy(char *dst, const char *src, size_t siz);
156 const char *osmo_strnchr(const char *str, size_t str_size, char c);
157
158 bool osmo_is_hexstr(const char *str, int min_digits, int max_digits,
159 bool require_even);
160
161 bool osmo_identifier_valid(const char *str);
162 bool osmo_separated_identifiers_valid(const char *str, const char *sep_chars);
163 void osmo_identifier_sanitize_buf(char *str, const char *sep_chars, char replace_with);
164
165 size_t osmo_escape_cstr_buf(char *buf, size_t bufsize, const char *str, int in_len);
166 char *osmo_escape_cstr_c(void *ctx, const char *str, int in_len);
167 size_t osmo_quote_cstr_buf(char *buf, size_t bufsize, const char *str, int in_len);
168 char *osmo_quote_cstr_c(void *ctx, const char *str, int in_len);
169
170 const char *osmo_escape_str(const char *str, int len);
171 int osmo_escape_str_buf3(char *buf, size_t bufsize, const char *str, int in_len);
172 char *osmo_escape_str_buf2(char *buf, size_t bufsize, const char *str, int in_len);
173 const char *osmo_escape_str_buf(const char *str, int in_len, char *buf, size_t bufsize);
174 char *osmo_escape_str_c(const void *ctx, const char *str, int in_len);
175 const char *osmo_quote_str(const char *str, int in_len);
176 int osmo_quote_str_buf3(char *buf, size_t bufsize, const char *str, int in_len);
177 char *osmo_quote_str_buf2(char *buf, size_t bufsize, const char *str, int in_len);
178 const char *osmo_quote_str_buf(const char *str, int in_len, char *buf, size_t bufsize);
179 char *osmo_quote_str_c(const void *ctx, const char *str, int in_len);
180
181 int osmo_print_n(char *buf, size_t bufsize, const char *str, size_t n);
182
183uint32_t osmo_isqrt32(uint32_t x);
184
189#define OSMO_MOD_FLR(x, y) (((x) > 0 && (y) < 0) || ((x) < 0 && (y) > 0) ? (x) % (y) + (y) : (x) % (y))
190
195#define OSMO_MOD_EUC(x, y) ((x) % (y) < 0 ? (y) > 0 ? (x) % (y) + (y) : (x) % (y) - (y) : (x) % (y))
196
197 char osmo_luhn(const char* in, int in_len);
198
200 struct osmo_strbuf {
202 char *buf;
204 size_t len;
206 char *pos;
210 size_t chars_needed;
211};
212
249#define OSMO_STRBUF_APPEND(STRBUF, func, args...) do { \
250 if (!(STRBUF).pos) \
251 (STRBUF).pos = (STRBUF).buf; \
252 size_t _sb_remain = OSMO_STRBUF_REMAIN(STRBUF); \
253 int _sb_l = func((STRBUF).pos, _sb_remain, ##args); \
254 if (_sb_l < 0 || (size_t)_sb_l > _sb_remain) \
255 (STRBUF).pos = (STRBUF).buf + (STRBUF).len; \
256 else if ((STRBUF).pos) \
257 (STRBUF).pos += _sb_l; \
258 if (_sb_l > 0) \
259 (STRBUF).chars_needed += _sb_l; \
260 } while(0)
261
281#define OSMO_STRBUF_PRINTF(STRBUF, fmt, args...) \
282 OSMO_STRBUF_APPEND(STRBUF, snprintf, fmt, ##args)
283
287 static inline size_t _osmo_strbuf_remain(const struct osmo_strbuf *sb)
288{
289 if (OSMO_UNLIKELY(sb == NULL || sb->buf == NULL))
290 return 0;
291 if (sb->pos == NULL)
292 return sb->len;
293 return sb->len - (sb->pos - sb->buf);
294}
295
297#define OSMO_STRBUF_REMAIN(STRBUF) \
298 _osmo_strbuf_remain(&(STRBUF))
299
303 static inline size_t _osmo_strbuf_char_count(const struct osmo_strbuf *sb)
304{
305 if (OSMO_UNLIKELY(sb == NULL || sb->buf == NULL))
306 return 0;
307 if (sb->pos == NULL || sb->pos <= sb->buf)
308 return 0;
309 return OSMO_MIN((size_t)(sb->pos - sb->buf), sb->len - 1);
310}
311
313#define OSMO_STRBUF_CHAR_COUNT(STRBUF) \
314 _osmo_strbuf_char_count(&(STRBUF))
315
324#define OSMO_STRBUF_APPEND_NOLEN(STRBUF, func, args...) do { \
325 if (!(STRBUF).pos) \
326 (STRBUF).pos = (STRBUF).buf; \
327 size_t _sb_remain = OSMO_STRBUF_REMAIN(STRBUF); \
328 if (_sb_remain) { \
329 func((STRBUF).pos, _sb_remain, ##args); \
330 } \
331 size_t _sb_l = (STRBUF).pos ? strnlen((STRBUF).pos, _sb_remain) : 0; \
332 if (_sb_l > _sb_remain) \
333 (STRBUF).pos = (STRBUF).buf + (STRBUF).len; \
334 else if ((STRBUF).pos) \
335 (STRBUF).pos += _sb_l; \
336 (STRBUF).chars_needed += _sb_l; \
337 } while(0)
338
339 void osmo_strbuf_drop_tail(struct osmo_strbuf *sb, size_t n_chars);
340/* Convenience macro. struct osmo_strbuf are typically static to a function scope. Avoid having to type '&', same as
341 * with all the other OSMO_STRBUF_* API. */
342#define OSMO_STRBUF_DROP_TAIL(STRBUF, N_CHARS) osmo_strbuf_drop_tail(&(STRBUF), N_CHARS)
343
344 void osmo_strbuf_added_tail(struct osmo_strbuf *sb, size_t n_chars);
345/* Convenience macro. struct osmo_strbuf are typically static to a function scope. Avoid having to type '&', same as
346 * with all the other OSMO_STRBUF_* API. */
347#define OSMO_STRBUF_ADDED_TAIL(STRBUF, N_CHARS) osmo_strbuf_added_tail(&(STRBUF), N_CHARS)
348
349 bool osmo_str_startswith(const char *str, const char *startswith_str);
350
351 int osmo_float_str_to_int(int64_t *val, const char *str, unsigned int precision);
352 int osmo_int_to_float_str_buf(char *buf, size_t buflen, int64_t val, unsigned int precision);
353 char *osmo_int_to_float_str_c(void *ctx, int64_t val, unsigned int precision);
354
355 int osmo_str_to_int64(int64_t *result, const char *str, int base, int64_t min_val, int64_t max_val);
356 int osmo_str_to_int(int *result, const char *str, int base, int min_val, int max_val);
357
382#define OSMO_NAME_C_IMPL(CTX, INITIAL_BUFSIZE, ON_ERROR, FUNC_BUF, FUNC_BUF_ARGS...) \
383 size_t _len = INITIAL_BUFSIZE; \
384 int _needed; \
385 char *_str = NULL; \
386 if ((INITIAL_BUFSIZE) > 0) { \
387 _str = (char*)talloc_named_const(CTX, _len, __func__); \
388 OSMO_ASSERT(_str); \
389 } \
390 _needed = FUNC_BUF(_str, _len, ## FUNC_BUF_ARGS); \
391 if (_needed < 0) \
392 goto OSMO_NAME_C_on_error; \
393 if ((unsigned int) _needed < _len) \
394 return _str; \
395 _len = _needed + 1; \
396 if (_str) \
397 talloc_free(_str); \
398 _str = (char*)talloc_named_const(CTX, _len, __func__); \
399 OSMO_ASSERT(_str); \
400 _needed = FUNC_BUF(_str, _len, ## FUNC_BUF_ARGS); \
401 if (_needed < 0) \
402 goto OSMO_NAME_C_on_error; \
403 return _str; \
404 OSMO_NAME_C_on_error: \
405 /* Re-using and re-sizing above allocated buf ends up in very complex code. Just free and strdup. */ \
406 if (_str) \
407 talloc_free(_str); \
408 if (!(ON_ERROR)) \
409 return NULL; \
410 _str = talloc_strdup(CTX, ON_ERROR); \
411 OSMO_ASSERT(_str); \
412 talloc_set_name_const(_str, __func__); \
413 return _str;
414
backtrace.h
defs.h
General definitions that are meant to be included from header files.
len
static size_t len(const char *str)
n
write Write running configuration to or terminal n Write configuration to the copy running config startup Copy configuration n Copy running config to n Copy running config to startup write Write running configuration to or terminal n Write to terminal n
__attribute__
enum gsm0808_assignment_requirement __attribute__
Definition: log2.h:61
data
uint8_t data[0]
OSMO_UNLIKELY
#define OSMO_UNLIKELY(exp)
Definition: utils.h:47
osmo_str_toupper
const char * osmo_str_toupper(const char *src)
Convert a string to uppercase, using a static buffer.
Definition: utils.c:1171
osmo_strbuf_added_tail
void osmo_strbuf_added_tail(struct osmo_strbuf *sb, size_t n_chars)
Let osmo_strbuf know that n_chars characters (excluding nul) were written to the end of the buffer.
Definition: utils.c:1248
OSMO_MIN
#define OSMO_MIN(a, b)
Return the minimum of two specified values.
Definition: utils.h:24
osmo_str_tolower_c
char * osmo_str_tolower_c(const void *ctx, const char *src)
Convert a string to lowercase, dynamically allocating the output from given talloc context See also o...
Definition: utils.c:1125
osmo_quote_cstr_buf
size_t osmo_quote_cstr_buf(char *buf, size_t bufsize, const char *str, int in_len)
Like osmo_escape_str_buf2(), but returns double-quotes around a string, or "NULL" for a NULL string.
Definition: utils.c:1018
_osmo_strbuf_remain
static size_t _osmo_strbuf_remain(const struct osmo_strbuf *sb)
Get remaining space for characters and terminating nul in the given struct osmo_strbuf.
Definition: utils.h:287
osmo_str_toupper_c
char * osmo_str_toupper_c(const void *ctx, const char *src)
Convert a string to uppercase, dynamically allocating the output from given talloc context See also o...
Definition: utils.c:1183
osmo_quote_cstr_c
char * osmo_quote_cstr_c(void *ctx, const char *str, int in_len)
Return the string quoted and with all non-printable characters escaped, in dynamically-allocated buff...
Definition: utils.c:1030
osmo_hexdump_buf
const char * osmo_hexdump_buf(char *out_buf, size_t out_buf_size, const unsigned char *buf, int len, const char *delim, bool delim_after_last)
Convert binary sequence to hexadecimal ASCII string.
Definition: utils.c:310
osmo_strlcpy
size_t osmo_strlcpy(char *dst, const char *src, size_t siz)
Copy a C-string into a sized buffer.
Definition: utils.c:575
osmo_strbuf_drop_tail
void osmo_strbuf_drop_tail(struct osmo_strbuf *sb, size_t n_chars)
Remove up to N chars from the end of an osmo_strbuf.
Definition: utils.c:1228
osmo_quote_str_c
char * osmo_quote_str_c(const void *ctx, const char *str, int in_len)
Like osmo_quote_str_buf() but returns the result in a dynamically-allocated buffer.
Definition: utils.c:972
osmo_strnchr
const char * osmo_strnchr(const char *str, size_t str_size, char c)
Find first occurence of a char in a size limited string.
Definition: utils.c:595
osmo_talloc_replace_string_fmt
void osmo_talloc_replace_string_fmt(void *ctx, char **dst, const char *fmt,...)
Replace a string using talloc and release its prior content (if any).
Definition: utils.c:1578
osmo_print_n
int osmo_print_n(char *buf, size_t bufsize, const char *str, size_t n)
Copy N characters to a buffer with a function signature useful for OSMO_STRBUF_APPEND().
Definition: utils.c:733
_osmo_strbuf_char_count
static size_t _osmo_strbuf_char_count(const struct osmo_strbuf *sb)
Get number of actual characters (without terminating nul) in the given struct osmo_strbuf.
Definition: utils.h:303
osmo_bcd2str
int osmo_bcd2str(char *dst, size_t dst_size, const uint8_t *bcd, int start_nibble, int end_nibble, bool allow_hex)
Convert BCD to string.
Definition: utils.c:157
osmo_talloc_replace_string
static void osmo_talloc_replace_string(void *ctx, char **dst, const char *newstr)
duplicate a string using talloc and release its prior content (if any)
Definition: utils.h:124
osmo_escape_str_c
char * osmo_escape_str_c(const void *ctx, const char *str, int in_len)
Return the string with all non-printable characters escaped, in dynamically-allocated buffer.
Definition: utils.c:875
osmo_ubit_dump_buf
char * osmo_ubit_dump_buf(char *buf, size_t buf_len, const uint8_t *bits, unsigned int len)
Convert a sequence of unpacked bits to ASCII string, in user-supplied buffer.
Definition: utils.c:352
osmo_str_startswith
bool osmo_str_startswith(const char *str, const char *startswith_str)
Compare start of a string.
Definition: utils.c:1274
get_string_value
int get_string_value(const struct value_string *vs, const char *str)
get numeric value for given human-readable string
Definition: utils.c:102
osmo_str_to_int
int osmo_str_to_int(int *result, const char *str, int base, int min_val, int max_val)
Convert a string of a number to int, including all common strtoll() validity checks.
Definition: utils.c:1552
osmo_quote_str_buf2
char * osmo_quote_str_buf2(char *buf, size_t bufsize, const char *str, int in_len)
Like osmo_escape_str_buf2(), but returns double-quotes around a string, or "NULL" for a NULL string.
Definition: utils.c:931
osmo_str_to_int64
int osmo_str_to_int64(int64_t *result, const char *str, int base, int64_t min_val, int64_t max_val)
Convert a string of a number to int64_t, including all common strtoll() validity checks.
Definition: utils.c:1493
osmo_decode_big_endian
uint64_t osmo_decode_big_endian(const uint8_t *data, size_t data_len)
Generic retrieval of 1..8 bytes as big-endian uint64_t.
Definition: utils.c:534
osmo_hexdump_nospc
char * osmo_hexdump_nospc(const unsigned char *buf, int len)
Convert binary sequence to hexadecimal ASCII string.
Definition: utils.c:439
osmo_ubit_dump
char * osmo_ubit_dump(const uint8_t *bits, unsigned int len)
Convert a sequence of unpacked bits to ASCII string, in static buffer.
Definition: utils.c:387
osmo_escape_str_buf3
int osmo_escape_str_buf3(char *buf, size_t bufsize, const char *str, int in_len)
Return the string with all non-printable characters escaped.
Definition: utils.c:841
osmo_str_toupper_buf
size_t osmo_str_toupper_buf(char *dest, size_t dest_len, const char *src)
Convert a string to uppercase, while checking buffer size boundaries.
Definition: utils.c:1145
osmo_identifier_sanitize_buf
void osmo_identifier_sanitize_buf(char *str, const char *sep_chars, char replace_with)
Replace characters in the given string buffer so that it is guaranteed to pass osmo_separated_identif...
Definition: utils.c:693
osmo_luhn
char osmo_luhn(const char *in, int in_len)
Calculate the Luhn checksum (as used for IMEIs).
Definition: utils.c:1198
osmo_str_tolower_buf
size_t osmo_str_tolower_buf(char *dest, size_t dest_len, const char *src)
Convert a string to lowercase, while checking buffer size boundaries.
Definition: utils.c:1087
osmo_int_to_float_str_c
char * osmo_int_to_float_str_c(void *ctx, int64_t val, unsigned int precision)
Convert an integer with a factor of a million to a floating point string.
Definition: utils.c:1474
osmo_osmo_hexdump_nospc
char * osmo_osmo_hexdump_nospc(const unsigned char *buf, int len) __attribute__((__deprecated__))
osmo_constant_time_cmp
int osmo_constant_time_cmp(const uint8_t *exp, const uint8_t *rel, const int count)
Wishful thinking to generate a constant time compare.
Definition: utils.c:512
osmo_isqrt32
uint32_t osmo_isqrt32(uint32_t x)
perform an integer square root operation on unsigned 32bit integer.
Definition: utils.c:1040
osmo_hexparse
int osmo_hexparse(const char *str, uint8_t *b, unsigned int max_len)
Parse a string containing hexadecimal digits.
Definition: utils.c:251
osmo_quote_str_buf3
int osmo_quote_str_buf3(char *buf, size_t bufsize, const char *str, int in_len)
Like osmo_escape_str_buf3(), but returns double-quotes around a string, or "NULL" for a NULL string.
Definition: utils.c:917
osmo_float_str_to_int
int osmo_float_str_to_int(int64_t *val, const char *str, unsigned int precision)
Convert a string of a floating point number to a signed int, with a decimal factor (fixed-point preci...
Definition: utils.c:1295
OSMO_DEPRECATED
#define OSMO_DEPRECATED(text)
Set the deprecated attribute with a message.
Definition: defs.h:41
osmo_bcd2char
char osmo_bcd2char(uint8_t bcd)
Convert BCD-encoded digit into printable character.
Definition: utils.c:119
osmo_escape_cstr_buf
size_t osmo_escape_cstr_buf(char *buf, size_t bufsize, const char *str, int in_len)
Return the string with all non-printable characters escaped.
Definition: utils.c:988
osmo_quote_str
const char * osmo_quote_str(const char *str, int in_len)
Like osmo_quote_str_buf() but returns the result in a static buffer.
Definition: utils.c:961
osmo_is_hexstr
bool osmo_is_hexstr(const char *str, int min_digits, int max_digits, bool require_even)
Validate that a given string is a hex string within given size limits.
Definition: utils.c:621
osmo_str2lower
void osmo_str2lower(char *out, const char *in) OSMO_DEPRECATED("Use osmo_str_tolower() or osmo_str_tolower_buf() instead
osmo_encode_big_endian
uint8_t * osmo_encode_big_endian(uint64_t value, size_t data_len)
Generic big-endian encoding of big endian number up to 64bit.
Definition: utils.c:555
osmo_str2bcd
int osmo_str2bcd(uint8_t *dst, size_t dst_size, const char *digits, int start_nibble, int end_nibble, bool allow_hex)
Convert string to BCD.
Definition: utils.c:202
osmo_escape_str_buf2
char * osmo_escape_str_buf2(char *buf, size_t bufsize, const char *str, int in_len)
Return the string with all non-printable characters escaped.
Definition: utils.c:853
osmo_escape_cstr_c
char * osmo_escape_cstr_c(void *ctx, const char *str, int in_len)
Return the string with all non-printable characters escaped, in dynamically-allocated buffer.
Definition: utils.c:1000
osmo_escape_str
const char * osmo_escape_str(const char *str, int len)
Return the string with all non-printable characters escaped.
Definition: utils.c:865
osmo_separated_identifiers_valid
bool osmo_separated_identifiers_valid(const char *str, const char *sep_chars)
Determine if a given identifier is valid, i.e.
Definition: utils.c:651
get_value_string_or_null
const char * get_value_string_or_null(const struct value_string *vs, uint32_t val)
get human-readable string or NULL for given value
Definition: utils.c:79
osmo_escape_str_buf
const char * osmo_escape_str_buf(const char *str, int in_len, char *buf, size_t bufsize)
Like osmo_escape_str_buf2, but with unusual ordering of arguments, and may sometimes return string co...
Definition: utils.c:716
osmo_str_tolower
const char * osmo_str_tolower(const char *src)
Convert a string to lowercase, using a static buffer.
Definition: utils.c:1113
osmo_quote_str_buf
const char * osmo_quote_str_buf(const char *str, int in_len, char *buf, size_t bufsize)
Like osmo_quote_str_buf2, but with unusual ordering of arguments, and may sometimes return string con...
Definition: utils.c:945
osmo_hexdump
char * osmo_hexdump(const unsigned char *buf, int len)
Convert binary sequence to hexadecimal ASCII string.
Definition: utils.c:403
osmo_identifier_valid
bool osmo_identifier_valid(const char *str)
Determine if a given identifier is valid, i.e.
Definition: utils.c:681
osmo_hexdump_c
char * osmo_hexdump_c(const void *ctx, const unsigned char *buf, int len)
Convert binary sequence to hexadecimal ASCII string.
Definition: utils.c:418
osmo_char2bcd
uint8_t osmo_char2bcd(char c)
Convert number in ASCII to BCD value.
Definition: utils.c:131
osmo_hexdump_nospc_c
char * osmo_hexdump_nospc_c(const void *ctx, const unsigned char *buf, int len)
Convert binary sequence to hexadecimal ASCII string.
Definition: utils.c:454
osmo_str2upper
void osmo_str2upper(char *out, const char *in) OSMO_DEPRECATED("Use osmo_str_toupper() or osmo_str_toupper_buf() instead
get_value_string
const char * get_value_string(const struct value_string *vs, uint32_t val)
get human-readable string for given value
Definition: utils.c:63
osmo_int_to_float_str_buf
int osmo_int_to_float_str_buf(char *buf, size_t buflen, int64_t val, unsigned int precision)
Convert an integer to a floating point string using a decimal quotient (fixed-point precision).
Definition: utils.c:1420
x
uint32_t x
Definition: jhash.h:0
panic.h
osmo_strbuf
State for OSMO_STRBUF_APPEND() and OSMO_STRBUF_PRINTF().
Definition: utils.h:200
osmo_strbuf::pos
char * pos
Current writing position in buf (end of the string written so far).
Definition: utils.h:206
osmo_strbuf::buf
char * buf
Point to the start of a string buffer.
Definition: utils.h:202
osmo_strbuf::len
size_t len
Total sizeof() the buffer buf points at.
Definition: utils.h:204
osmo_strbuf::chars_needed
size_t chars_needed
After all OSMO_STRBUF_APPEND operations, reflects the total number of characters that would be writte...
Definition: utils.h:210
value_string
A mapping between human-readable string and numeric value.
Definition: utils.h:51
value_string::value
uint32_t value
numeric value
Definition: utils.h:52
value_string::str
const char * str
human-readable string
Definition: utils.h:53
talloc.h