|
x-engine-c v0.2.13
The C engine for x-lang
|
C standard library replacements. More...
#include "x-sys.h"Go to the source code of this file.
Functions | |
Standard Library Replacements | |
| int | x_lib_abs (int i) |
| void * | x_lib_memcpy (void *p_dest, const void *p_src, size_t n) |
| void * | x_lib_memset (void *p_dest, int byte, size_t size) |
| char * | x_lib_strchr (const char *p_str, int c) |
| int | x_lib_strcmp (const char *p_str1, const char *p_str2) |
| size_t | x_lib_strlen (const char *p_str) |
| int | x_lib_strncmp (const char *p_str1, const char *p_str2, size_t n) |
| char * | x_lib_strndup (const char *p_str, size_t size) |
C standard library replacements.
Stand-ins for standard C library functions, for builds where the stdlib is not available (freestanding targets, embedders that supply their own runtime). When X_USE_STDLIB is defined each function is a light wrapper delegating to the real one; otherwise the self-contained implementation is used.
The C standard owns everything about these functions: the semantics, and the types in the prototypes – plain char/void/int/ size_t, never the x layer's typedefs. The x_lib_ prefix is the one deliberate difference: it lets the replacements coexist with a real libc in the same link. General-purpose helpers with their own contracts live in x-lib.h, not here.
., .,
{O,O}
( )
" "
| int x_lib_abs | ( | int | i | ) |
Compute the absolute value of an integer.
Compute the absolute value of an integer.
| i | The integer value. |
i. | void * x_lib_memcpy | ( | void * | p_dest, |
| const void * | p_src, | ||
| size_t | size | ||
| ) |
Copy bytes from a source buffer to a destination buffer.
Copy bytes from a source buffer to a destination buffer.
| p_dest | Pointer to the destination buffer. |
| p_src | Pointer to the source buffer. |
| size | Number of bytes to copy. |
p_dest. | void * x_lib_memset | ( | void * | p_dest, |
| int | byte, | ||
| size_t | size | ||
| ) |
Fill a memory region with a constant byte.
Fill a memory region with a constant byte.
| p_dest | Pointer to the destination buffer. |
| byte | The byte value to fill with. |
| size | Number of bytes to set. |
p_dest. | char * x_lib_strchr | ( | const char * | p_str, |
| int | c | ||
| ) |
Locate the first occurrence of a character in a string.
Locate the first occurrence of a character in a string.
c is converted to char before comparing, and the terminating NUL is part of the string (C99 7.24.5.2): searching for '\0' returns the terminator.
| p_str | The string to search. |
| c | The character to find (as an int). |
| int x_lib_strcmp | ( | const char * | p_str1, |
| const char * | p_str2 | ||
| ) |
Compare two null-terminated strings.
Compare two null-terminated strings.
Bytes compare as unsigned char (C99 7.24.4), independent of the platform's plain-char signedness.
| p_str1 | First string. |
| p_str2 | Second string. |
| size_t x_lib_strlen | ( | const char * | p_str | ) |
Calculate the length of a null-terminated string.
Calculate the length of a null-terminated string.
| p_str | The string to measure. |
| int x_lib_strncmp | ( | const char * | p_str1, |
| const char * | p_str2, | ||
| size_t | n | ||
| ) |
Compare two strings up to a maximum number of characters.
Compare two strings up to a maximum of n characters.
Bytes compare as unsigned char (C99 7.24.4); n == 0 compares nothing and returns 0.
| p_str1 | First string. |
| p_str2 | Second string. |
| n | Maximum number of characters to compare. |
| char * x_lib_strndup | ( | const char * | p_str, |
| size_t | size | ||
| ) |
Duplicate at most size characters of a string (POSIX.1-2008).
Duplicate at most size characters of a string.
The copy stops at the first NUL or after size characters, whichever comes first, and is always NUL-terminated; at most size source bytes are read.
| p_str | The source string. |
| size | Maximum number of characters to copy. |