Cross-platform C SDK logo

Cross-platform C SDK

Standard functions

❮ Back
Next ❯
This page has been automatically translated using the Google Translate API services. We are working on improving texts. Thank you for your understanding and patience.

Functions

uint32_tblib_strlen (...)
const char_t*blib_strstr (...)
voidblib_strcpy (...)
voidblib_strncpy (...)
voidblib_strcat (...)
intblib_strcmp (...)
intblib_strncmp (...)
int64_tblib_strtol (...)
uint64_tblib_strtoul (...)
real32_tblib_strtof (...)
real64_tblib_strtod (...)
voidblib_qsort (...)
voidblib_qsort_ex (...)
bool_tblib_bsearch (...)
bool_tblib_bsearch_ex (...)
voidblib_atexit (...)
voidblib_abort (void)
voidblib_debug_break (void)

BLib includes useful functions from the C standard library that don't fit in other modules like BMath or BMem. As in <stdlib.h> we find text conversion functions, algorithms or interaction with the environment.


blib_strlen ()

Returns the length in bytes of a text string.

uint32_t
blib_strlen(const char_t *str);
str

String terminated with null character '\0'.

Return

String length not including the null character.

Remarks

See Unicode, the number of bytes is not equivalent to the number of characters.


blib_strstr ()

Find a substring within a longer string.

const char_t*
blib_strstr(const char_t *str,
            const char_t *substr);
str

String terminated with null character '\0'.

substr

Substring to search ending in null character '\0'.

Return

Pointer to the start of the first substring found or NULL if none exists.


blib_strcpy ()

Copy the content of one string to another.

void
blib_strcpy(char_t *dest,
            const uint32_t size,
            const char_t *src);
dest

Destiny buffer.

size

Destination buffer size in bytes.

src

String to copy ending in null character '\0'.

Remarks

Only the first size-1 bytes will be copied, in case src is longer than the capacity of dest.


blib_strncpy ()

Copy the first n bytes of one string to another.

void
blib_strncpy(const char_t *dest,
             const uint32_t size,
             const char_t *src,
             const uint32_t n);
dest

Destiny buffer.

size

Destination buffer size in bytes.

src

String to copy ending in null character '\0'.

n

Number of bytes to copy.

Remarks

Only the first size-1 bytes will be copied, in case n is greater than size.


blib_strcat ()

Concatenation of strings.

void
blib_strcat(char_t *dest,
            const uint32_t size,
            const char_t *src);
dest

Source and destination buffer.

size

Destination buffer size in bytes.

src

String to add to dest, terminated with null character '\0'.

Remarks

The size-1 bytes in dest will not be exceeded, so the concatenation will be truncated if necessary.


blib_strcmp ()

Compare two strings.

int
blib_strcmp(const char_t *str1,
            const char_t *str2);
str1

First string to compare, terminated with null character '\0'.

str2

Second string to compare, terminated with null character '\0'.

Return

Comparison Result.


blib_strncmp ()

Compare the first n bytes of two strings.

int
blib_strncmp(const char_t *str1,
             const char_t *str2,
             const uint32_t n);
str1

First string to compare, terminated with null character '\0'.

str2

Second string to compare, terminated with null character '\0'.

n

Maximum number of bytes to compare.

Return

Comparison Result.


blib_strtol ()

Convert a text string to an integer.

int64_t
blib_strtol(const char_t *str,
            char_t **endptr,
            uint32_t base,
            bool_t *err);
str

String starting with an integer.

endptr

Pointer whose value will be the first character after the number. Can be NULL.

base

Number base: 2, 8, 10, 16.

err

Value TRUE is assigned if there is an error in the parsing of the string. Can be NULL.

Return

String parsing result number.


blib_strtoul ()

Convert a text string to an unsigned integer.

uint64_t
blib_strtoul(const char_t *str,
             char_t **endptr,
             uint32_t base,
             bool_t *err);
str

String starting with an integer.

endptr

Pointer whose value will be the first character after the number. Can be NULL.

base

Number base: 2, 8, 10, 16.

err

Value TRUE is assigned if there is an error in the parsing of the string. Can be NULL.

Return

String parsing result number.


blib_strtof ()

Convert a text string to a 32-bit real number.

real32_t
blib_strtof(const char_t *str,
            char_t **endptr,
            bool_t *err);
str

String starting with an real number.

endptr

Pointer whose value will be the first character after the number. Can be NULL.

err

Value TRUE is assigned if there is an error in the parsing of the string. Can be NULL.

Return

String parsing result number.


blib_strtod ()

Convert a text string to a 32-bit real number.

real64_t
blib_strtod(const char_t *str,
            char_t **endptr,
            bool_t *err);
str

String starting with an real number.

endptr

Pointer whose value will be the first character after the number. Can be NULL.

err

Value TRUE is assigned if there is an error in the parsing of the string. Can be NULL.

Return

String parsing result number.


blib_qsort ()

Sorts a vector of elements using the QuickSort algorithm.

void
blib_qsort(byte_t *array,
           const uint32_t nelems,
           const uint32_t size,
           FPtr_compare func_compare);
array

Vector of elements.

nelems

Number of elements.

size

Size of each element.

func_compare

Comparison function.


blib_qsort_ex ()

Sorts a vector of elements using the QuickSort algorithm.

void
blib_qsort_ex(byte_t *array,
              const uint32_t nelems,
              const uint32_t size,
              FPtr_compare_ex func_compare,
              const byte_t *data);
array

Vector of elements.

nelems

Number of elements.

size

Size of each element.

func_compare

Compare function that accepts extra data.

data

Extra data that will be passed in each comparison.


blib_bsearch ()

Search for an element in an ordered vector.

bool_t
blib_bsearch(const byte_t *array,
             const byte_t *key,
             const uint32_t nelems,
             const uint32_t size,
             FPtr_compare func_compare,
             uint32_t *pos);
array

Vector of elements.

key

Search key.

nelems

Number of elements.

size

Size of each element.

func_compare

Comparison function.

pos

Position of the found element. It can be NULL.

Return

TRUE if the element was found.


blib_bsearch_ex ()

Search for an element in an ordered vector.

bool_t
blib_bsearch_ex(const byte_t *array,
                const byte_t *key,
                const uint32_t nelems,
                const uint32_t size,
                FPtr_compare_ex func_compare,
                const byte_t *data,
                uint32_t *pos);
array

Vector of elements.

key

Search key.

nelems

Number of elements.

size

Size of each element.

func_compare

Compare function that accepts extra data.

data

Extra data that will be passed in each comparison.

pos

Position of the found element. It can be NULL.

Return

TRUE if the element was found.


blib_atexit ()

Add a function that will be called when the program ends.

void
blib_atexit(void()(void) *func);
func

Function.


blib_abort ()

The execution of the program ends abruptly.

void
blib_abort(void);

Remarks

No resources are released or a controlled shutdown is performed. The only case where its use is justified is to exit the program after detecting an unrecoverable error (eg NULL pointer).


blib_debug_break ()

Stops program execution at the point where the function is located and returns debugger control so we can inspect the stack, variables, etc.

void
blib_debug_break(void);
❮ Back
Next ❯