Minimal string and memory manipulation functions for bare-metal AArch64.
More...
#include <stddef.h>
Go to the source code of this file.
|
| void * | memcpy (void *dest, const void *src, size_t size) |
| | Copies size bytes from memory area src to memory area dest.
|
| |
| int | memcmp (const void *str1, const void *str2, size_t size) |
| | Compares the first size bytes of memory areas str1 and str2.
|
| |
| void * | memchr (const void *str, int chr, size_t size) |
| | Scans memory for a specific character.
|
| |
| void * | memmove (void *dest, const void *src, size_t size) |
| | Copies size bytes from memory area src to memory area dest.
|
| |
| void * | memset (void *s_ptr, int val, size_t size) |
| | Fills the first size bytes of the memory area pointed to by s_ptr with the constant byte val.
|
| |
| int | memset_s (void *dest, size_t destsz, int byte, size_t count) |
| | Bounds-checked fill of dest with a constant byte.
|
| |
| char * | strchr (const char *str, int chr) |
| | Locate the first occurrence of a character in a string.
|
| |
| char * | strrchr (const char *str, int chr) |
| | Locates the last occurrence of a character in a string.
|
| |
| size_t | strlen (const char *str) |
| | Calculates the length of a string.
|
| |
| size_t | strnlen (const char *str, size_t maxlen) |
| | Calculates the length of a string up to a specified maximum.
|
| |
| unsigned long | strtoul (const char *nptr, char **endptr, int base) |
| | Convert a string to an unsigned long integer.
|
| |
| int | strcmp (const char *lhs, const char *rhs) |
| | Compare two null-terminated strings.
|
| |
Minimal string and memory manipulation functions for bare-metal AArch64.
Provides essential string and memory helpers used by the kernel and linked external libraries in a freestanding runtime environment.
- Author
- Abhin Parekadan Jose
- Date
- 2026-05-16
◆ memchr()
| void * memchr |
( |
const void * |
str, |
|
|
int |
chr, |
|
|
size_t |
size |
|
) |
| |
Scans memory for a specific character.
Searches the first size bytes of the memory area pointed to by str for the first occurrence of chr.
- Parameters
-
| str | Pointer to the memory area. |
| chr | The character to search for (interpreted as an unsigned char). |
| size | The number of bytes to analyze. |
- Returns
- A pointer to the matching byte, or NULL if the character is not found.
◆ memcmp()
| int memcmp |
( |
const void * |
str1, |
|
|
const void * |
str2, |
|
|
size_t |
size |
|
) |
| |
Compares the first size bytes of memory areas str1 and str2.
- Parameters
-
| str1 | Pointer to the first memory block. |
| str2 | Pointer to the second memory block. |
| size | Number of bytes to compare. |
- Returns
- An integer less than, equal to, or greater than zero if
str1 is found, respectively, to be less than, to match, or be greater than str2.
◆ memcpy()
| void * memcpy |
( |
void * |
dest, |
|
|
const void * |
src, |
|
|
size_t |
size |
|
) |
| |
Copies size bytes from memory area src to memory area dest.
- Note
- The memory areas must not overlap. Use memmove() if they do.
- Parameters
-
| dest | Pointer to the destination array. |
| src | Pointer to the source of data to be copied. |
| size | Number of bytes to copy. |
- Returns
- A pointer to the destination
dest.
◆ memmove()
| void * memmove |
( |
void * |
dest, |
|
|
const void * |
src, |
|
|
size_t |
size |
|
) |
| |
Copies size bytes from memory area src to memory area dest.
- Note
- The memory areas may overlap: copying takes place as though the bytes in
src are first copied into a temporary array that does not overlap src or dest.
- Parameters
-
| dest | Pointer to the destination array. |
| src | Pointer to the source of data to be copied. |
| size | Number of bytes to copy. |
- Returns
- A pointer to the destination
dest.
◆ memset()
| void * memset |
( |
void * |
s_ptr, |
|
|
int |
val, |
|
|
size_t |
size |
|
) |
| |
Fills the first size bytes of the memory area pointed to by s_ptr with the constant byte val.
- Parameters
-
| s_ptr | Pointer to the memory area to fill. |
| val | The byte value to set. |
| size | Number of bytes to be set to the value. |
- Returns
- A pointer to the memory area
s_ptr.
◆ memset_s()
| int memset_s |
( |
void * |
dest, |
|
|
size_t |
destsz, |
|
|
int |
byte, |
|
|
size_t |
count |
|
) |
| |
Bounds-checked fill of dest with a constant byte.
Writes count copies of byte into dest after validating that the write fits within destsz. The operation is rejected if dest is NULL, destsz is zero, or count exceeds destsz.
- Parameters
-
| dest | Pointer to the memory area to fill. |
| destsz | Size of the destination buffer, in bytes. |
| byte | The byte value to write. |
| count | Number of bytes to set. |
- Returns
- 0 on success, or -1 if the arguments fail validation.
◆ strchr()
| char * strchr |
( |
const char * |
str, |
|
|
int |
chr |
|
) |
| |
Locate the first occurrence of a character in a string.
- Parameters
-
| str | The string to search. |
| chr | The character to look for (passed as int, converted to char). |
- Returns
- A pointer to the matched character, or NULL if not found.
◆ strcmp()
| int strcmp |
( |
const char * |
lhs, |
|
|
const char * |
rhs |
|
) |
| |
Compare two null-terminated strings.
- Parameters
-
| lhs | The first string to compare. |
| rhs | The second string to compare. |
- Returns
- 0 if the strings are equal.
- A negative value if
lhs is less than rhs.
- A positive value if
lhs is greater than rhs.
◆ strlen()
| size_t strlen |
( |
const char * |
str | ) |
|
Calculates the length of a string.
Scans the string str until the terminating null byte ('\0') is found.
- Parameters
-
| str | Pointer to the null-terminated string. |
- Returns
- The number of characters in the string, excluding the null byte.
◆ strnlen()
| size_t strnlen |
( |
const char * |
str, |
|
|
size_t |
maxlen |
|
) |
| |
Calculates the length of a string up to a specified maximum.
Similar to strlen(), but scans at most maxlen bytes.
- Parameters
-
| str | Pointer to the string. |
| maxlen | The maximum number of bytes to examine. |
- Returns
- The number of characters in the string if less than
maxlen; otherwise, maxlen.
◆ strrchr()
| char * strrchr |
( |
const char * |
str, |
|
|
int |
chr |
|
) |
| |
Locates the last occurrence of a character in a string.
Scans the string str to find the last occurrence of character chr.
- Parameters
-
| str | Pointer to the null-terminated string. |
| chr | The character to search for. |
- Returns
- A pointer to the last occurrence of the character, or NULL if not found.
◆ strtoul()
| unsigned long strtoul |
( |
const char * |
nptr, |
|
|
char ** |
endptr, |
|
|
int |
base |
|
) |
| |
Convert a string to an unsigned long integer.
- Parameters
-
| nptr | The string containing the representation of the number. |
| endptr | Pointer to the character that stopped the scan. |
| base | The radix to use (e.g., 10 for decimal, 16 for hex). |
- Returns
- The converted value.