|
Kernelite 0.1.0
Kernelite is a minimalist, educational operating system kernel built from scratch. The project aims to recreate core components of the Linux architecture to explore the fundamentals of operating system design and hardware-software interaction.
|
Implementation of minimal string and memory helper functions. More...
#include "utils/string.h"
Functions | |
| 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. | |
Implementation of minimal string and memory helper functions.
Provides a small set of freestanding string and memory operations required by the kernel and linked external libraries.
| 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.
| str | Pointer to the memory area. |
| chr | The character to search for (interpreted as an unsigned char). |
| size | The number of bytes to analyze. |
| int memcmp | ( | const void * | str1, |
| const void * | str2, | ||
| size_t | size | ||
| ) |
Compares the first size bytes of memory areas str1 and str2.
| str1 | Pointer to the first memory block. |
| str2 | Pointer to the second memory block. |
| size | Number of bytes to compare. |
str1 is found, respectively, to be less than, to match, or be greater than str2. | void * memcpy | ( | void * | dest, |
| const void * | src, | ||
| size_t | size | ||
| ) |
Copies size bytes from memory area src to memory area dest.
| dest | Pointer to the destination array. |
| src | Pointer to the source of data to be copied. |
| size | Number of bytes to copy. |
dest. | void * memmove | ( | void * | dest, |
| const void * | src, | ||
| size_t | size | ||
| ) |
Copies size bytes from memory area src to memory area dest.
src are first copied into a temporary array that does not overlap src or dest.| dest | Pointer to the destination array. |
| src | Pointer to the source of data to be copied. |
| size | Number of bytes to copy. |
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.
| 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. |
s_ptr. | 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.
| 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. |
| char * strchr | ( | const char * | str, |
| int | chr | ||
| ) |
Locate the first occurrence of a character in a string.
| str | The string to search. |
| chr | The character to look for (passed as int, converted to char). |
| int strcmp | ( | const char * | lhs, |
| const char * | rhs | ||
| ) |
Compare two null-terminated strings.
| lhs | The first string to compare. |
| rhs | The second string to compare. |
lhs is less than rhs.lhs is greater than rhs. | size_t strlen | ( | const char * | str | ) |
Calculates the length of a string.
Scans the string str until the terminating null byte ('\0') is found.
| str | Pointer to the null-terminated string. |
| 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.
| str | Pointer to the string. |
| maxlen | The maximum number of bytes to examine. |
maxlen; otherwise, maxlen. | 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.
| str | Pointer to the null-terminated string. |
| chr | The character to search for. |
| unsigned long strtoul | ( | const char * | nptr, |
| char ** | endptr, | ||
| int | base | ||
| ) |
Convert a string to an unsigned long integer.
| 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). |