|
x-engine-c v0.2.13
The C engine for x-lang
|
Implementation of the general-purpose library helpers. More...
Macros | |
| #define | BREAK_ON_BASE |
Functions | |
| x_char_t * | x_lib_inttostr (x_int_t num, x_char_t *p_str, unsigned short base) |
| void * | x_lib_memdup (const void *p_src, size_t size) |
| x_int_t | x_lib_strtoint (const x_char_t *p_str, x_char_t **pp_end, unsigned short base) |
Implementation of the general-purpose library helpers.
These carry x-expr's own contracts (x types are honest here). The C standard library replacements live in x-stdlib.c.
., .,
{O,O}
( )
" "
| #define BREAK_ON_BASE |
Convert an integer to a string representation.
Converts num into an ASCII string stored in p_str using the given numeric base (2–36). If base is greater than 10, digits after '9' use lowercase letters starting with 'a'. If num is negative, a minus sign is prepended.
p_str. The minimum buffer size depends on the base. For base 2 (binary), the buffer needs at least 8 * sizeof(x_int_t) + 1 bytes.| num | The integer to convert. |
| p_str | Destination buffer for the resulting string. |
| base | Numeric base (2–36). |
p_str, or NULL if arguments are invalid. | void * x_lib_memdup | ( | const void * | p_src, |
| size_t | size | ||
| ) |
Duplicate a memory region.
Allocates a new buffer via x_sys_malloc() and copies size bytes from p_src into it. If p_src is NULL, the buffer is allocated but not copied (and optionally zeroed if X_OPT_MEMZERO is defined).
| p_src | Pointer to the source memory, or NULL. |
| size | Number of bytes to duplicate. |
Convert a string to an integer.
Parses p_str as a signed integer in the given base (2–36). If base is 0, the base is auto-detected from the prefix: 0x for hexadecimal, 0 for octal, otherwise decimal.
Leading whitespace is skipped. An optional + or - sign is accepted. If pp_end is non-NULL, it is set to point past the last parsed character.
| p_str | The string to parse. |
| pp_end | Output: pointer past the last parsed character, or NULL. |
| base | Numeric base (0 for auto-detect, or 2–36). |