paw: spkg: Add more string functions

Signed-off-by: Chloe M. <chloe@mensia.org>
This commit is contained in:
Chloe M.
2026-06-22 03:36:13 +00:00
parent b588cc0217
commit f38cd9e619
4 changed files with 123 additions and 0 deletions
+23
View File
@@ -0,0 +1,23 @@
/*
* Copyright (c) 2026, Chloe M.
* Provided under the BSD-3 clause.
*
* Description: RtlMemCpy() implementation
* Author: Chloe M.
*/
#include <string.h>
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;
}
+45
View File
@@ -0,0 +1,45 @@
/*
* Copyright (c) 2026, Chloe M.
* Provided under the BSD-3 clause.
*
* Description: RtlMemSet() implementation
* Author: Chloe M.
*/
#include <string.h>
#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;
}
+24
View File
@@ -0,0 +1,24 @@
/*
* Copyright (c) 2026, Chloe M.
* Provided under the BSD-3 clause.
*
* Description: RtlStrLen() implementation
* Author: Chloe M.
*/
#include <string.h>
USIZE
RtlStrLen(const CHAR *String)
{
USIZE Length = 0;
if (String == NULL) {
return 0;
}
while (String[Length++] != '\0')
;
return Length;
}