paw: spkg: Add more string functions
Signed-off-by: Chloe M. <chloe@mensia.org>
This commit is contained in:
@@ -22,4 +22,35 @@
|
|||||||
*/
|
*/
|
||||||
LONG RtlMemCmp(const VOID *Buffer1, const VOID *Buffer2, USIZE Length);
|
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_ */
|
#endif /* !_SPKG_STRING_H_ */
|
||||||
|
|||||||
@@ -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;
|
||||||
|
}
|
||||||
@@ -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;
|
||||||
|
}
|
||||||
@@ -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;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user