YAMI4Industry
Functions
utils.c File Reference
#include "utils.h"
#include <stddef.h>
#include <stdint.h>

Functions

size_t yami_round_up_to_4 (const size_t v)
 Rounds the given value to the nearest 4 (for alignment). More...
 
size_t yami_round_up_to_8 (const size_t v)
 Rounds the given value to the nearest 8 (for alignment). More...
 
size_t yami_strlen (const char s[])
 Replacement for standard strlen. More...
 
int32_t yami_strcmp (const char s1[], const char s2[])
 Replacement for standard strcmp. More...
 
int32_t yami_strncmp (const char s1[], const char s2[], const size_t n)
 Replacement for standard strncmp. More...
 
void yami_strncpy (char dest[], const char src[], const size_t n)
 Replacement for standard strncpy. More...
 
int32_t yami_strfind (const char s[], const char c, const size_t from, const size_t to)
 Finds the given character in nul-terminated string. More...
 
void yami_memcpy (uint8_t dest[], const size_t dest_from, const uint8_t src[], const size_t src_from, const size_t n)
 Replacement for standard memcpy. More...
 
void yami_bzero (uint8_t dest[], const size_t n)
 Replacement for standard bzero. More...
 
int32_t yami_uint32_to_string (uint32_t v, char buf[], const size_t buf_from, const size_t buf_size)
 Converts uint32_t to string format. More...
 
int32_t yami_string_to_uint32 (const char buf[], const size_t from, const size_t to, uint32_t *const out_value)
 Converts nul-terminated string to uint32_t. More...
 
int32_t yami_string_to_uint8 (const char buf[], const size_t from, const size_t to, uint8_t *const out_value)
 Converts nul-terminated string to uint8_t. More...
 

Function Documentation

void yami_bzero ( uint8_t  dest[],
const size_t  n 
)

Replacement for standard bzero.

void yami_memcpy ( uint8_t  dest[],
const size_t  dest_from,
const uint8_t  src[],
const size_t  src_from,
const size_t  n 
)

Replacement for standard memcpy.

size_t yami_round_up_to_4 ( size_t  v)

Rounds the given value to the nearest 4 (for alignment).

Parameters
vvalue to round
Returns
value rounded up to the nearset 4 boundary
size_t yami_round_up_to_8 ( size_t  v)

Rounds the given value to the nearest 8 (for alignment).

Parameters
vvalue to round
Returns
value rounded up to the nearset 8 boundary
int32_t yami_strcmp ( const char  s1[],
const char  s2[] 
)

Replacement for standard strcmp.

int32_t yami_strfind ( const char  s[],
char  c,
size_t  from,
size_t  to 
)

Finds the given character in nul-terminated string.

Parameters
sstring to be searched in
ccharacter to be searched for
fromstarting index in s
tolast (not inclusive) index in s
Returns
index or -1 if the given character is not found.
int32_t yami_string_to_uint32 ( const char  buf[],
size_t  from,
size_t  to,
uint32_t *  out_value 
)

Converts nul-terminated string to uint32_t.

Parameters
bufstring to be converted
fromstarting index in buf
tolast (not inclusive) index in buf
out_valuevalue after conversion
Returns
1 on success or 0 if the given string cannot be converted to number
int32_t yami_string_to_uint8 ( const char  buf[],
size_t  from,
size_t  to,
uint8_t *  out_value 
)

Converts nul-terminated string to uint8_t.

Parameters
bufstring to be converted
fromstarting index in buf
tolast (not inclusive) index in buf
out_valuevalue after conversion
Returns
1 on success or 0 if the given string cannot be converted to number
size_t yami_strlen ( const char  s[])

Replacement for standard strlen.

int32_t yami_strncmp ( const char  s1[],
const char  s2[],
const size_t  n 
)

Replacement for standard strncmp.

void yami_strncpy ( char  dest[],
const char  src[],
const size_t  n 
)

Replacement for standard strncpy.

int32_t yami_uint32_to_string ( uint32_t  v,
char  buf[],
size_t  buf_from,
size_t  buf_size 
)

Converts uint32_t to string format.

Parameters
vvalue to be converted
bufbuffer where the string will be formatted
buf_fromstarting index in buf
buf_sizetotal size of buf
Returns
index of last character in buf or -1 if buf_size is not big enough