Soletta™ Framework
|
Contains helpers to manipulate time, error code/string, overflows, encode/decode data and some converters. More...
Modules | |
Soletta file utility functions | |
Contains helpers to deal with files. | |
Macros | |
#define | sol_util_array_size(arr) (sizeof(arr) / sizeof((arr)[0])) |
Calculates the number of elements in an array. More... | |
#define | sol_util_max(x, y) |
Gets the maximum value. More... | |
#define | sol_util_min(x, y) |
Gets the minimum value. More... | |
#define | SOL_UTIL_MSEC_PER_SEC 1000ULL |
number of milliseconds in a second: 1,000. More... | |
#define | SOL_UTIL_NSEC_PER_MSEC 1000000ULL |
number of nanoseconds in a milliseconds: 1,000,000,000 / 1,000 = 1,000,000. More... | |
#define | SOL_UTIL_NSEC_PER_SEC 1000000000ULL |
number of nanoseconds in a second: 1,000,000,000. More... | |
#define | SOL_UTIL_NSEC_PER_USEC 1000ULL |
number of nanoseconds in a microsecond: 1,000,000,000 / 1,000,000 = 1,000. More... | |
#define | sol_util_strerrora(errnum) |
Gets a string from a given error using the stack. More... | |
#define | sol_util_uint16_bytes_swap(val) ((uint16_t)((((val) >> 8) & 0xff) | (((val) & 0xff) << 8))) |
Swaps the bytes of a 16 bytes unsigned int. More... | |
#define | sol_util_uint32_bytes_swap(val) |
Swaps the bytes of a 32 bytes unsigned int. More... | |
#define | sol_util_uint64_bytes_swap(val) |
Swaps the bytes of a 32 bytes unsigned int. More... | |
#define | SOL_UTIL_USEC_PER_SEC 1000000ULL |
number of microseconds in a second: 1,000,000. More... | |
Functions | |
static ssize_t | sol_util_base16_calculate_decoded_len (const struct sol_str_slice slice) |
Calculate the size necessary to decode a given slice in base16. More... | |
static ssize_t | sol_util_base16_calculate_encoded_len (const struct sol_str_slice slice) |
Calculate the size necessary to encode a given slice in base16. More... | |
ssize_t | sol_util_base16_decode (void *buf, size_t buflen, const struct sol_str_slice slice, enum sol_decode_case decode_case) |
Decode the binary slice from base16 (hexadecimal). More... | |
ssize_t | sol_util_base16_encode (void *buf, size_t buflen, const struct sol_str_slice slice, bool uppercase) |
Encode the binary slice to base16 (hexadecimal). More... | |
ssize_t | sol_util_base64_calculate_decoded_len (const struct sol_str_slice slice, const char base64_map[SOL_STATIC_ARRAY_SIZE(65)]) |
Calculate the size necessary to decode a given slice in base64. More... | |
static ssize_t | sol_util_base64_calculate_encoded_len (const struct sol_str_slice slice, const char base64_map[SOL_STATIC_ARRAY_SIZE(65)]) |
Calculate the size necessary to encode a given slice in base64. More... | |
ssize_t | sol_util_base64_decode (void *buf, size_t buflen, const struct sol_str_slice slice, const char base64_map[SOL_STATIC_ARRAY_SIZE(65)]) |
Decode the binary slice from base64 using the given map. More... | |
ssize_t | sol_util_base64_encode (void *buf, size_t buflen, const struct sol_str_slice slice, const char base64_map[SOL_STATIC_ARRAY_SIZE(65)]) |
Encode the binary slice to base64 using the given map. More... | |
static uint16_t | sol_util_be16_to_cpu (uint16_t val) |
Convert a 16 bytes big endian integer to cpu endianness. More... | |
static uint32_t | sol_util_be32_to_cpu (uint32_t val) |
Convert a 32 bytes big endian integer to cpu endianness. More... | |
static uint64_t | sol_util_be64_to_cpu (uint64_t val) |
Convert a 64 bytes big endian integer to cpu endianness. More... | |
static void | sol_util_clear_memory_secure (void *buf, size_t len) |
Clear an allocated memory securely. More... | |
static uint16_t | sol_util_cpu_to_be16 (uint16_t val) |
Convert a 16 bytes integer to big endian format. More... | |
static uint32_t | sol_util_cpu_to_be32 (uint32_t val) |
Convert a 32 bytes integer to big endian format. More... | |
static uint64_t | sol_util_cpu_to_be64 (uint64_t val) |
Convert a 64 bytes integer to big endian format. More... | |
static uint16_t | sol_util_cpu_to_le16 (uint16_t val) |
Convert a 16 bytes integer to little endian format. More... | |
static uint32_t | sol_util_cpu_to_le32 (uint32_t val) |
Convert a 32 bytes integer to little endian format. More... | |
static uint64_t | sol_util_cpu_to_le64 (uint64_t val) |
Convert a 64 bytes integer to little endian format. More... | |
bool | sol_util_double_eq (double var0, double var1) |
Checks var0 and var1 for equality. More... | |
static int32_t | sol_util_int32_clamp (int32_t start, int32_t end, int32_t value) |
Restricts a number between two other numbers. More... | |
int | sol_util_int32_mul (int32_t op1, int32_t op2, int32_t *out) |
Multiply two values checking for overflow. More... | |
int | sol_util_int64_mul (int64_t op1, int64_t op2, int64_t *out) |
Multiply two values checking for overflow. More... | |
static uint16_t | sol_util_le16_to_cpu (uint16_t val) |
Convert a 16 bytes little endian integer to cpu endianness. More... | |
static uint32_t | sol_util_le32_to_cpu (uint32_t val) |
Convert a 32 bytes little endian integer to cpu endianness. More... | |
static uint64_t | sol_util_le64_to_cpu (uint64_t val) |
Convert a 64 bytes little endian integer to cpu endianness. More... | |
void * | sol_util_memdup (const void *data, size_t len) |
Duplicate memory. More... | |
static int | sol_util_msec_from_timespec (const struct timespec *ts) |
Gets the number of milliseconds for given time. More... | |
int | sol_util_replace_str_from_slice_if_changed (char **str, const struct sol_str_slice slice) |
Replace the string's contents. More... | |
int | sol_util_replace_str_if_changed (char **str, const char *new_str) |
Replace the string's contents. More... | |
int | sol_util_size_add (size_t op1, size_t op2, size_t *out) |
Add two values checking for overflow. More... | |
int | sol_util_size_mul (size_t op1, size_t op2, size_t *out) |
Multiply two values checking for overflow. More... | |
int | sol_util_size_sub (size_t op1, size_t op2, size_t *out) |
Subtract two values checking for overflow. More... | |
int | sol_util_ssize_mul (ssize_t op1, ssize_t op2, ssize_t *out) |
Multiply two values checking for overflow. More... | |
char * | sol_util_strerror (int errnum, struct sol_buffer *buf) |
Gets a string from a given error. More... | |
ssize_t | sol_util_strftime (struct sol_buffer *buf, const char *format, const struct tm *timeptr, bool use_locale) SOL_ATTR_STRFTIME(2) |
Wrapper around strftime()/strftime_l() More... | |
double | sol_util_strtod_n (const char *nptr, char **endptr, ssize_t len, bool use_locale) |
Wrapper over strtod() that consumes up to len bytes and may not use a locale. More... | |
long int | sol_util_strtol_n (const char *nptr, char **endptr, ssize_t len, int base) |
Wrapper over strtol() that consumes up to len bytes. More... | |
unsigned long int | sol_util_strtoul_n (const char *nptr, char **endptr, ssize_t len, int base) |
Wrapper over strtoul() that consumes up to len bytes. More... | |
static void | sol_util_timespec_add (const struct timespec *t1, const struct timespec *t2, struct timespec *result) |
Sum two time values. More... | |
static int | sol_util_timespec_compare (const struct timespec *t1, const struct timespec *t2) |
Compare two time values. More... | |
static struct timespec | sol_util_timespec_from_msec (int msec) |
Create a struct timespec from milliseconds. More... | |
static struct timespec | sol_util_timespec_from_usec (int usec) |
Create a struct timespec from microseconds. More... | |
struct timespec | sol_util_timespec_get_current (void) |
Gets the current time (Monotonic). More... | |
int | sol_util_timespec_get_realtime (struct timespec *t) |
Gets the current time (System-wide clock). More... | |
static void | sol_util_timespec_sub (const struct timespec *t1, const struct timespec *t2, struct timespec *result) |
Subtracts two time values. More... | |
int | sol_util_uint32_mul (uint32_t op1, uint32_t op2, uint32_t *out) |
Multiply two values checking for overflow. More... | |
int | sol_util_uint64_add (uint64_t op1, uint64_t op2, uint64_t *out) |
Add two values checking for overflow. More... | |
int | sol_util_uint64_mul (uint64_t op1, uint64_t op2, uint64_t *out) |
Multiply two values checking for overflow. More... | |
int | sol_util_unescape_quotes (const struct sol_str_slice slice, struct sol_buffer *buf) |
Unescape a string removing quotes from it. More... | |
int32_t | sol_util_unicode_code_from_utf8 (const uint8_t *buf, size_t buf_len, uint8_t *bytes_read) |
Convert a utf-8 character to unicode code. More... | |
static int | sol_util_usec_from_timespec (const struct timespec *ts) |
Gets the number of microseconds for given time. More... | |
int8_t | sol_util_utf8_from_unicode_code (uint8_t *buf, size_t buf_len, uint32_t unicode_code) |
Convert from unicode code to utf-8 string. More... | |
int | sol_util_uuid_bytes_from_string (struct sol_str_slice uuid_str, struct sol_buffer *uuid_bytes) |
Convert a UUID in string format to a byte array with UUID bytes. More... | |
int | sol_util_uuid_gen (bool uppercase, bool with_hyphens, struct sol_buffer *uuid_buf) |
Generates a new universally unique identifier (UUID) string. More... | |
bool | sol_util_uuid_str_is_valid (const struct sol_str_slice uuid) |
Checks if a given universally unique identifier (UUID), in string form, is valid. More... | |
int | sol_util_uuid_string_from_bytes (bool uppercase, bool with_hyphens, const uint8_t uuid_bytes[SOL_STATIC_ARRAY_SIZE(16)], struct sol_buffer *uuid_str) |
Convert a UUID in byte format to UUID string format. More... | |
Contains helpers to manipulate time, error code/string, overflows, encode/decode data and some converters.
#define sol_util_array_size | ( | arr | ) | (sizeof(arr) / sizeof((arr)[0])) |
Calculates the number of elements in an array.
Referenced by create_location_obj(), delete_all_cb(), write_sec_one_cb(), and write_server_one_cb().
#define sol_util_max | ( | x, | |
y | |||
) |
Gets the maximum value.
This will generate shadowing warnings if the same kind is nested, but the warnings on type mismatch are a fair benefit.
Use temporary variables to address nested call cases.
#define sol_util_min | ( | x, | |
y | |||
) |
Gets the minimum value.
This will generate shadowing warnings if the same kind is nested, but the warnings on type mismatch are a fair benefit.
Use temporary variables to address nested call cases.
#define SOL_UTIL_MSEC_PER_SEC 1000ULL |
number of milliseconds in a second: 1,000.
Referenced by sol_util_msec_from_timespec(), and sol_util_timespec_from_msec().
#define SOL_UTIL_NSEC_PER_MSEC 1000000ULL |
number of nanoseconds in a milliseconds: 1,000,000,000 / 1,000 = 1,000,000.
Referenced by sol_util_msec_from_timespec(), and sol_util_timespec_from_msec().
#define SOL_UTIL_NSEC_PER_SEC 1000000000ULL |
number of nanoseconds in a second: 1,000,000,000.
Referenced by print_time(), sol_util_timespec_add(), and sol_util_timespec_sub().
#define SOL_UTIL_NSEC_PER_USEC 1000ULL |
number of nanoseconds in a microsecond: 1,000,000,000 / 1,000,000 = 1,000.
Referenced by sol_util_timespec_from_usec(), and sol_util_usec_from_timespec().
#define sol_util_strerrora | ( | errnum | ) |
Gets a string from a given error using the stack.
The function returns a pointer to a string (created using the stack) that describes the error code passed in the argument errnum
.
errnum | The error code |
Referenced by get_int32_packet_and_log(), mavlink_connect_cb(), mission_reached_cb(), mode_changed_cb(), on_feed_done(), on_stdin(), on_stdin_hash(), position_changed_cb(), producer_data_written(), producer_make_data(), send_blob(), startup(), startup_server(), and takeoff().
#define sol_util_uint16_bytes_swap | ( | val | ) | ((uint16_t)((((val) >> 8) & 0xff) | (((val) & 0xff) << 8))) |
Swaps the bytes of a 16 bytes unsigned int.
Referenced by sol_util_be16_to_cpu(), sol_util_cpu_to_be16(), sol_util_cpu_to_le16(), and sol_util_le16_to_cpu().
#define sol_util_uint32_bytes_swap | ( | val | ) |
Swaps the bytes of a 32 bytes unsigned int.
Referenced by sol_util_be32_to_cpu(), sol_util_cpu_to_be32(), sol_util_cpu_to_le32(), and sol_util_le32_to_cpu().
#define sol_util_uint64_bytes_swap | ( | val | ) |
Swaps the bytes of a 32 bytes unsigned int.
Referenced by sol_util_be64_to_cpu(), sol_util_cpu_to_be64(), sol_util_cpu_to_le64(), and sol_util_le64_to_cpu().
#define SOL_UTIL_USEC_PER_SEC 1000000ULL |
number of microseconds in a second: 1,000,000.
Referenced by sol_util_timespec_from_usec(), and sol_util_usec_from_timespec().
|
inlinestatic |
Calculate the size necessary to decode a given slice in base16.
slice | The slice that is wanted to know the decoded size. |
slice
or a negative number on error. References sol_str_slice::len.
|
inlinestatic |
Calculate the size necessary to encode a given slice in base16.
slice | The slice that is wanted to know the encoded size. |
slice
or a negative number on error. References sol_str_slice::len, and sol_util_ssize_mul().
ssize_t sol_util_base16_decode | ( | void * | buf, |
size_t | buflen, | ||
const struct sol_str_slice | slice, | ||
enum sol_decode_case | decode_case | ||
) |
Decode the binary slice from base16 (hexadecimal).
buf | a buffer of size buflen that is big enough to hold the decoded string. |
buflen | the number of bytes available in buffer. Must be large enough to contain the decoded slice, that is: slice.len / 2. |
slice | the slice to decode, it must be a set of 0-9 or letters A-F (if uppercase) or a-f, otherwise decode fails. |
decode_case | if SOL_DECODE_UPPERCASE, uppercase letters ABCDEF are used, if SOL_DECODE_LOWERCASE, lowercase abcdef are used instead. If SOL_DECODE_BOTH both, lowercase and uppercase, letters can be used. |
Referenced by main().
ssize_t sol_util_base16_encode | ( | void * | buf, |
size_t | buflen, | ||
const struct sol_str_slice | slice, | ||
bool | uppercase | ||
) |
Encode the binary slice to base16 (hexadecimal).
buf | a buffer of size buflen that is big enough to hold the encoded string. |
buflen | the number of bytes available in buffer. Must be large enough to contain the encoded slice, that is: slice.len * 2 |
slice | the slice to encode, it may contain null-bytes (\0), the whole size of the slice will be used (slice.len). |
uppercase | if true, uppercase letters ABCDEF are used, otherwise lowercase abcdef are used instead. |
ssize_t sol_util_base64_calculate_decoded_len | ( | const struct sol_str_slice | slice, |
const char | base64_map[SOL_STATIC_ARRAY_SIZE(65)] | ||
) |
Calculate the size necessary to decode a given slice in base64.
slice | The slice that is wanted to know the decode size. |
base64_map | the map to use. The last char is used as the padding character if slice length is not multiple of 3 bytes. |
slice
or a negative number on error.
|
inlinestatic |
Calculate the size necessary to encode a given slice in base64.
slice | The slice that is wanted to know the encoded size. |
base64_map | the map to use. The last char is used as the padding character if slice length is not multiple of 3 bytes. |
slice
or a negative number on error. References sol_str_slice::len, and sol_util_ssize_mul().
ssize_t sol_util_base64_decode | ( | void * | buf, |
size_t | buflen, | ||
const struct sol_str_slice | slice, | ||
const char | base64_map[SOL_STATIC_ARRAY_SIZE(65)] | ||
) |
Decode the binary slice from base64 using the given map.
https://en.wikipedia.org/wiki/Base64
buf | a buffer of size buflen that is big enough to hold the decoded string. |
buflen | the number of bytes available in buffer. Must be large enough to contain the decoded slice, that is: (slice.len / 4) * 3 |
slice | the slice to decode, it must be composed solely of the base64_map characters or it will fail. |
base64_map | the map to use. The last char is used as the padding character if slice length is not multiple of 3 bytes. |
ssize_t sol_util_base64_encode | ( | void * | buf, |
size_t | buflen, | ||
const struct sol_str_slice | slice, | ||
const char | base64_map[SOL_STATIC_ARRAY_SIZE(65)] | ||
) |
Encode the binary slice to base64 using the given map.
https://en.wikipedia.org/wiki/Base64
buf | a buffer of size buflen that is big enough to hold the encoded string. |
buflen | the number of bytes available in buffer. Must be large enough to contain the encoded slice, that is: (slice.len / 3 + 1) * 4 |
slice | the slice to encode, it may contain null-bytes (\0), the whole size of the slice will be used (slice.len). |
base64_map | the map to use. The last char is used as the padding character if slice length is not multiple of 3 bytes. |
|
inlinestatic |
Convert a 16 bytes big endian integer to cpu endianness.
This function converts a integer of 16 bytes to little endian format, in case of the integer being in the cpu endiannesst nothing is done.
val | the uint16_t number to convert. |
References sol_util_uint16_bytes_swap.
Referenced by sol_network_link_addr_eq_full().
|
inlinestatic |
Convert a 32 bytes big endian integer to cpu endianness.
This function converts a integer of 32 bytes to little endian format, in case of the integer being in the cpu endiannesst nothing is done.
val | the uint32_t number to convert. |
References sol_util_uint32_bytes_swap.
|
inlinestatic |
Convert a 64 bytes big endian integer to cpu endianness.
This function converts a integer of 64 bytes to little endian format, in case of the integer being in the cpu endiannesst nothing is done.
val | the uint64_t number to convert. |
References sol_util_uint64_bytes_swap.
|
inlinestatic |
Clear an allocated memory securely.
Clobber memory pointed to by buf
to prevent the optimizer from eliding the memset()
call.
buf | The memory block |
len | The buf length |
|
inlinestatic |
Convert a 16 bytes integer to big endian format.
This function converts a integer of 16 bytes to big endian format, in case of the integer being in big endian format nothing is done.
val | the uint16_t number to convert. |
References sol_util_uint16_bytes_swap.
|
inlinestatic |
Convert a 32 bytes integer to big endian format.
This function converts a integer of 32 bytes to big endian format, in case of the integer being in big endian format nothing is done.
val | the uint32_t number to convert. |
References sol_util_uint32_bytes_swap.
|
inlinestatic |
Convert a 64 bytes integer to big endian format.
This function converts a integer of 64 bytes to big endian format, in case of the integer being in big endian format nothing is done.
val | the uint64_t number to convert. |
References sol_util_uint64_bytes_swap.
|
inlinestatic |
Convert a 16 bytes integer to little endian format.
This function converts a integer of 16 bytes to little endian format, in case of the integer being in little endian format nothing is done.
val | the uint16_t number to convert. |
References sol_util_uint16_bytes_swap.
|
inlinestatic |
Convert a 32 bytes integer to little endian format.
This function converts a integer of 32 bytes to little endian format, in case of the integer being in little endian format nothing is done.
val | the uint32_t number to convert. |
References sol_util_uint32_bytes_swap.
|
inlinestatic |
Convert a 64 bytes integer to little endian format.
This function converts a integer of 64 bytes to little endian format, in case of the integer being in little endian format nothing is done.
val | the uint64_t number to convert. |
References sol_util_uint64_bytes_swap.
bool sol_util_double_eq | ( | double | var0, |
double | var1 | ||
) |
Checks var0
and var1
for equality.
It uses relative comparison to account for impressions caused by floating point arithmetics, so give preference to use this function instead of comparing the numbers directly.
var0 | First argument |
var1 | Second argument |
true
if both values are equal, false
otherwise.
|
inlinestatic |
Restricts a number between two other numbers.
start | Minimum value. |
end | Maximum value. |
value | The value to clamp. |
value
if living in the range imposed by the start
and end
, the lower value if initially lower than start
, or the higher one if initially higher than end
. References value.
int sol_util_int32_mul | ( | int32_t | op1, |
int32_t | op2, | ||
int32_t * | out | ||
) |
Multiply two values checking for overflow.
This function multiplies two variables of the type int32_t
and check if this operation causes an overflow.
op1 | First operation's operator. |
op2 | Second operation's operator. |
out | Variable used to store the result. |
0
on success, error code (always negative) otherwise. int sol_util_int64_mul | ( | int64_t | op1, |
int64_t | op2, | ||
int64_t * | out | ||
) |
Multiply two values checking for overflow.
This function multiply two variables of the type int64_t
and check if this operation causes an overflow.
op1 | First operation's operator. |
op2 | Second operation's operator. |
out | Variable used to store the result. |
0
on success, error code (always negative) otherwise.
|
inlinestatic |
Convert a 16 bytes little endian integer to cpu endianness.
This function converts a integer of 16 bytes to little endian format, in case of the integer being in the cpu endianness nothing is done.
val | the uint16_t number to convert. |
References sol_util_uint16_bytes_swap.
|
inlinestatic |
Convert a 32 bytes little endian integer to cpu endianness.
This function converts a integer of 32 bytes to little endian format, in case of the integer being in the cpu endianness nothing is done.
val | the uint32_t number to convert. |
References sol_util_uint32_bytes_swap.
|
inlinestatic |
Convert a 64 bytes little endian integer to cpu endianness.
This function converts a integer of 64 bytes to little endian format, in case of the integer being in the cpu endianness nothing is done.
val | the uint64_t number to convert. |
References sol_util_uint64_bytes_swap.
void* sol_util_memdup | ( | const void * | data, |
size_t | len | ||
) |
Duplicate memory.
It's a helper function to allocated memory and copy data, returning the pointer to it.
data | Pointer to the memory to be copied |
len | Size in bytes of the memory to be allocated |
NULL
if it fails to allocate it. The pointer need to be freed after usage.
|
inlinestatic |
Gets the number of milliseconds for given time.
ts | The struct timespec to get the milliseconds. |
ts
. References SOL_UTIL_MSEC_PER_SEC, and SOL_UTIL_NSEC_PER_MSEC.
int sol_util_replace_str_from_slice_if_changed | ( | char ** | str, |
const struct sol_str_slice | slice | ||
) |
Replace the string's contents.
This function takes a string and replace its contents if different from the new given slice, otherwise it lets the string intact.
str | The pointer for string which will be changed. |
slice | The slice with string |
1
if changed, 0 if unchanged, error code (always negative) otherwise.int sol_util_replace_str_if_changed | ( | char ** | str, |
const char * | new_str | ||
) |
Replace the string's contents.
This function takes a string and replace its contents if different from the new given string, otherwise it lets the string intact.
str | The pointer for string which will be changed. |
new_str | The new string |
1
if changed, 0 if unchanged, error code (always negative) otherwise.int sol_util_size_add | ( | size_t | op1, |
size_t | op2, | ||
size_t * | out | ||
) |
Add two values checking for overflow.
This function adds two variables of the type size_t
and check if this operation causes an overflow.
op1 | First operation's operator. |
op2 | Second operation's operator. |
out | Variable used to store the result. |
0
on success, error code (always negative) otherwise.int sol_util_size_mul | ( | size_t | op1, |
size_t | op2, | ||
size_t * | out | ||
) |
Multiply two values checking for overflow.
This function multiply two variables of the type size_t
and check if this operation causes an overflow.
op1 | First operation's operator. |
op2 | Second operation's operator. |
out | Variable used to store the time. |
0
on success, error code (always negative) otherwise.Referenced by _sol_glib_integration_source_prepare().
int sol_util_size_sub | ( | size_t | op1, |
size_t | op2, | ||
size_t * | out | ||
) |
Subtract two values checking for overflow.
This function subtracts two variables of the type size_t
and check if this operation causes an overflow.
op1 | First operation's operator. |
op2 | Second operation's operator. |
out | Variable used to store the result. |
0
on success, error code (always negative) otherwise.int sol_util_ssize_mul | ( | ssize_t | op1, |
ssize_t | op2, | ||
ssize_t * | out | ||
) |
Multiply two values checking for overflow.
This function multiply two variables of the type ssize_t
and check if this operation causes an overflow.
op1 | First operation's operator. |
op2 | Second operation's operator. |
out | Variable used to store the result. |
0
on success, error code (always negative) otherwise.Referenced by sol_util_base16_calculate_encoded_len(), and sol_util_base64_calculate_encoded_len().
char* sol_util_strerror | ( | int | errnum, |
struct sol_buffer * | buf | ||
) |
Gets a string from a given error.
The function returns a pointer to a string that describes the error code passed in the argument errnum
.
errnum | The error code |
buf | Buffer used to append error the string - It must be already initialized. |
ssize_t sol_util_strftime | ( | struct sol_buffer * | buf, |
const char * | format, | ||
const struct tm * | timeptr, | ||
bool | use_locale | ||
) |
Wrapper around strftime()/strftime_l()
This is a simple wrapper around strftime()/strftime_l() functions. The use_locale
parameter is only considered if strftime_l() and newlocale() are available, otherwise this wrapper will fallback to strftime() - Thus current system's locale will be considered when formatting the time.
buf | The buffer to append the formatted time to - It must be already initialzed. |
format | The date format - check strftime man page for accepted formats. |
timeptr | The broken down time struct. |
use_locale | true to use current system locale or false to do not use system's locale. |
double sol_util_strtod_n | ( | const char * | nptr, |
char ** | endptr, | ||
ssize_t | len, | ||
bool | use_locale | ||
) |
Wrapper over strtod() that consumes up to len
bytes and may not use a locale.
This variation of strtod() will work with buffers that are not null-terminated.
It also offers a way to skip the currently set locale, forcing plain "C". This is required to parse numbers in formats that require '.' as the decimal point while the current locale may use ',' such as in pt_BR.
All the formats accepted by strtod() are accepted and the behavior should be the same, including using information from LC_NUMERIC
if locale is configured and use_locale is true.
nptr | the string containing the number to convert. |
endptr | if non-NULL, it will contain the last character used in the conversion. If no conversion was done, endptr is nptr. |
use_locale | if true, then current locale is used, if false then "C" locale is forced. |
len | use at most this amount of bytes of nptr. If -1, assumes nptr has a trailing NUL and calculate the string length. |
NAN
, INF
(positive or negative). See the strtod(3) documentation for the details. Referenced by create_location_obj().
long int sol_util_strtol_n | ( | const char * | nptr, |
char ** | endptr, | ||
ssize_t | len, | ||
int | base | ||
) |
Wrapper over strtol() that consumes up to len
bytes.
This variation of strtol() will work with buffers that are not null-terminated.
All the formats accepted by strtol() are accepted and the behavior should be the same.
nptr | the string containing the number to convert. |
endptr | if non-NULL, it will contain the last character used in the conversion. If no conversion was done, endptr is nptr. |
len | use at most this amount of bytes of nptr. If -1, assumes nptr has a trailing NUL and calculate the string length. |
base | it's the base of conversion, which must be between 2 and 36 inclusive, or be the special value 0. A zero base is taken as 10 (decimal) unless the next character is '0', in which case it is taken as 8 (octal). |
unsigned long int sol_util_strtoul_n | ( | const char * | nptr, |
char ** | endptr, | ||
ssize_t | len, | ||
int | base | ||
) |
Wrapper over strtoul() that consumes up to len
bytes.
This variation of strtoul() will work with buffers that are not null-terminated.
All the formats accepted by strtoul() are accepted and the behavior should be the same.
nptr | the string containing the number to convert. |
endptr | if non-NULL, it will contain the last character used in the conversion. If no conversion was done, endptr is nptr. |
len | use at most this amount of bytes of nptr. If -1, assumes nptr has a trailing NUL and calculate the string length. |
base | it's the base of conversion, which must be between 2 and 36 inclusive, or be the special value 0. A zero base is taken as 10 (decimal) unless the next character is '0', in which case it is taken as 8 (octal). |
|
inlinestatic |
Sum two time values.
t1 | First time value used on operation. |
t2 | Second time value used on operation. |
result | Variable used to store the sum's result. |
References SOL_UTIL_NSEC_PER_SEC.
|
inlinestatic |
Compare two time values.
Function to compare two times. It returns an integer less than, equal to, or greater than zero.
t1 | First time value used on operation. |
t2 | Second time value used on operation. |
|
static |
Create a struct
timespec from milliseconds.
msec | The number of milliseconds. |
struct
timespec representing msec
milliseconds. References SOL_UTIL_MSEC_PER_SEC, and SOL_UTIL_NSEC_PER_MSEC.
Referenced by _sol_glib_integration_source_get_next_timeout().
|
static |
Create a struct
timespec from microseconds.
usec | The number of microseconds. |
struct
timespec representing usec
microseconds. References SOL_UTIL_NSEC_PER_USEC, and SOL_UTIL_USEC_PER_SEC.
struct timespec sol_util_timespec_get_current | ( | void | ) |
Gets the current time (Monotonic).
struct
timespec. Referenced by print_time(), and startup().
int sol_util_timespec_get_realtime | ( | struct timespec * | t | ) |
Gets the current time (System-wide clock).
t | Variable used to store the time. |
|
inlinestatic |
Subtracts two time values.
t1 | First time value used on operation. |
t2 | Second time value used on operation. |
result | Variable used to store the subtraction's result. |
References SOL_UTIL_NSEC_PER_SEC.
Referenced by print_time().
int sol_util_uint32_mul | ( | uint32_t | op1, |
uint32_t | op2, | ||
uint32_t * | out | ||
) |
Multiply two values checking for overflow.
This function multiplies two variables of the type int64_t
and check if this operation causes an overflow.
op1 | First operation's operator. |
op2 | Second operation's operator. |
out | Variable used to store the result. |
0
on success, error code (always negative) otherwise. int sol_util_uint64_add | ( | uint64_t | op1, |
uint64_t | op2, | ||
uint64_t * | out | ||
) |
Add two values checking for overflow.
This function add two variables of the type uint64_t
and check if this operation causes an overflow.
op1 | First operation's operator. |
op2 | Second operation's operator. |
out | Variable used to store the result. |
0
on success, error code (always negative) otherwise.int sol_util_uint64_mul | ( | uint64_t | op1, |
uint64_t | op2, | ||
uint64_t * | out | ||
) |
Multiply two values checking for overflow.
This function multiply two unsigned variables of the type uint64_t
and check if this operation causes an overflow.
op1 | First operation's operator. |
op2 | Second operation's operator. |
out | Variable used to store the result. |
0
on success, error code (always negative) otherwise.int sol_util_unescape_quotes | ( | const struct sol_str_slice | slice, |
struct sol_buffer * | buf | ||
) |
Unescape a string removing quotes from it.
This function will unescape single quotes (\') and double quotes (") from the slice, it will also remove single and double quotes from the string if they are not escaped. Trying to unescape a character that is not a single quote or double quote it is also considered an error.
slice | The slice to be escaped |
buf | - The buffer to hold the unescaped string - It will be initialized by this function. |
int32_t sol_util_unicode_code_from_utf8 | ( | const uint8_t * | buf, |
size_t | buf_len, | ||
uint8_t * | bytes_read | ||
) |
Convert a utf-8 character to unicode code.
buf | Buffer with the utf-8 representation of the unicode character. |
buf_len | The buffer length. |
bytes_read | Optional pointer to variable to write number of bytes read from buf. |
|
inlinestatic |
Gets the number of microseconds for given time.
ts | The struct timespec to get the microseconds. |
ts
. References SOL_UTIL_NSEC_PER_USEC, and SOL_UTIL_USEC_PER_SEC.
int8_t sol_util_utf8_from_unicode_code | ( | uint8_t * | buf, |
size_t | buf_len, | ||
uint32_t | unicode_code | ||
) |
Convert from unicode code to utf-8 string.
Write at string buf the bytes needed to represent the unicode charater informed as utf-8. One to four characters will be written on success. No character is written on error.
buf | Buffer to write the utf-8 representation of the unicode character |
buf_len | The buffer length |
unicode_code | Code from unicode table of the character to be converted |
int sol_util_uuid_bytes_from_string | ( | struct sol_str_slice | uuid_str, |
struct sol_buffer * | uuid_bytes | ||
) |
Convert a UUID in string format to a byte array with UUID bytes.
uuid_str | The UUID in string format, with or without hyphens, using lowercase or uppercase characters. |
uuid_bytes | an initialized buffer to be used to append the converted uuid, totalizing 16 bytes. |
int sol_util_uuid_gen | ( | bool | uppercase, |
bool | with_hyphens, | ||
struct sol_buffer * | uuid_buf | ||
) |
Generates a new universally unique identifier (UUID) string.
The generated string is 16 bytes-long (128 bits) long and conforms to v4 UUIDs (generated from random—or pseudo-random—numbers).
uppercase | Whether to generate the UUID in uppercase or not |
with_hyphens | Format the resulting UUID string with hyphens (e.g. "de305d54-75b4-431b-adb2-eb6b9e546014") or without them. |
uuid_buf | An initialized buffer to be used to append the generated id. It will have 36 bytes of length if with_hyphens is true or 32 bytes of length if with_hyphens is false. |
Referenced by producer_make_data().
bool sol_util_uuid_str_is_valid | ( | const struct sol_str_slice | uuid | ) |
Checks if a given universally unique identifier (UUID), in string form, is valid.
All upcase/downcase, hyphenated/non-hyphenated cases are included.
uuid | The given UUID formatted in a string, with or without hyphens. |
true
if it's valid, false
otherwise. int sol_util_uuid_string_from_bytes | ( | bool | uppercase, |
bool | with_hyphens, | ||
const uint8_t | uuid_bytes[SOL_STATIC_ARRAY_SIZE(16)], | ||
struct sol_buffer * | uuid_str | ||
) |
Convert a UUID in byte format to UUID string format.
uppercase | Whether to create the UUID string in uppercase or not |
with_hyphens | Format the resulting UUID string with hyphens (e.g. "de305d54-75b4-431b-adb2-eb6b9e546014") or without them. |
uuid_bytes | A 16 byte array containing the UUID in byte format. |
uuid_str | n initialized buffer to be used to append the converted uuid. It will have 36 bytes of length if with_hyphens is true or 32 bytes of length if with_hyphens is false. |