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.
Loading...
Searching...
No Matches
Functions
string.h File Reference

Minimal string and memory manipulation functions for bare-metal AArch64. More...

#include <stddef.h>
Include dependency graph for string.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

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.
 

Detailed Description

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

Function Documentation

◆ 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
strPointer to the memory area.
chrThe character to search for (interpreted as an unsigned char).
sizeThe 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
str1Pointer to the first memory block.
str2Pointer to the second memory block.
sizeNumber 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
destPointer to the destination array.
srcPointer to the source of data to be copied.
sizeNumber 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
destPointer to the destination array.
srcPointer to the source of data to be copied.
sizeNumber 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_ptrPointer to the memory area to fill.
valThe byte value to set.
sizeNumber 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
destPointer to the memory area to fill.
destszSize of the destination buffer, in bytes.
byteThe byte value to write.
countNumber 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
strThe string to search.
chrThe 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
lhsThe first string to compare.
rhsThe 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
strPointer 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
strPointer to the string.
maxlenThe 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
strPointer to the null-terminated string.
chrThe 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
nptrThe string containing the representation of the number.
endptrPointer to the character that stopped the scan.
baseThe radix to use (e.g., 10 for decimal, 16 for hex).
Returns
The converted value.