diff --git a/paw/spkg/head/string.h b/paw/spkg/head/string.h index d7cfbf3..87834f1 100644 --- a/paw/spkg/head/string.h +++ b/paw/spkg/head/string.h @@ -22,4 +22,35 @@ */ LONG RtlMemCmp(const VOID *Buffer1, const VOID *Buffer2, USIZE Length); +/* + * Obtain the length in bytes of a '\0' terminated string + * + * @String: String to obtain length from + * + * Returns zero on failure + */ +USIZE RtlStrLen(const CHAR *String); + +/* + * Fill n bytes of a buffer with a value + * + * @Buffer: Pointer to buffer to fill + * @SetValue: Value to fill with + * @Length: Number of bytes to fill + * + * Returns @Buffer on success, otherwise NULL on failure + */ +VOID *RtlMemSet(VOID *Buffer, LONG SetValue, USIZE Length); + +/* + * Copy n bytes of one buffer to another + * + * @Dest: Destination buffer + * @Soruce: Source buffer + * @Length: Length of buffers + * + * Returns @Dest on suucess, otherwise NULL on failure + */ +VOID *RtlMemCpy(VOID *Dest, const VOID *Source, USIZE Length); + #endif /* !_SPKG_STRING_H_ */ diff --git a/paw/spkg/lib/memcpy.c b/paw/spkg/lib/memcpy.c new file mode 100644 index 0000000..d3f2924 --- /dev/null +++ b/paw/spkg/lib/memcpy.c @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2026, Chloe M. + * Provided under the BSD-3 clause. + * + * Description: RtlMemCpy() implementation + * Author: Chloe M. + */ + +#include + +VOID * +RtlMemCpy(VOID *Dest, const VOID *Source, USIZE Length) +{ + if (Dest == NULL || Source == NULL) { + return NULL; + } + + for (USIZE Idx = 0; Idx < Length; ++Idx) { + ((UCHAR *)Dest)[Idx] = ((UCHAR *)Source)[Idx]; + } + + return Dest; +} diff --git a/paw/spkg/lib/memset.c b/paw/spkg/lib/memset.c new file mode 100644 index 0000000..d0293c8 --- /dev/null +++ b/paw/spkg/lib/memset.c @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2026, Chloe M. + * Provided under the BSD-3 clause. + * + * Description: RtlMemSet() implementation + * Author: Chloe M. + */ + +#include + +#ifndef __x86_64__ +#error "64-bit only" +#else +#define WORD_SHIFT 3 +#endif /* !__x86_64__ */ + +VOID * +RtlMemSet(VOID *Buffer, LONG SetValue, USIZE Length) +{ + USIZE WordCount; + USIZE *WordBuffer; + CHAR *ByteBuffer = (CHAR *)Buffer; + USIZE Index; + + if (Buffer == NULL || Length == 0) { + return NULL; + } + + /* How many words can this fit? */ + WordCount = Length / sizeof(USIZE); + WordBuffer = (USIZE *)Buffer; + + /* Fill as many words as we can */ + for (Index = 0; Index < WordCount; ++Index) { + WordBuffer[Index] = SetValue; + } + + /* Fill the rest */ + Index <<= WORD_SHIFT; + for (; Index < Length; ++Index) { + ByteBuffer[Index] = SetValue; + } + + return Buffer; +} diff --git a/paw/spkg/lib/strlen.c b/paw/spkg/lib/strlen.c new file mode 100644 index 0000000..73df898 --- /dev/null +++ b/paw/spkg/lib/strlen.c @@ -0,0 +1,24 @@ +/* + * Copyright (c) 2026, Chloe M. + * Provided under the BSD-3 clause. + * + * Description: RtlStrLen() implementation + * Author: Chloe M. + */ + +#include + +USIZE +RtlStrLen(const CHAR *String) +{ + USIZE Length = 0; + + if (String == NULL) { + return 0; + } + + while (String[Length++] != '\0') + ; + + return Length; +}