forked from xt-sys/exectos
Implement RtlStringLength() and RtlStringToWideString() routines
This commit is contained in:
parent
0ead750489
commit
b1c08e4a9f
@ -67,6 +67,17 @@ RtlSetMemory(OUT PVOID Destination,
|
|||||||
IN UCHAR Byte,
|
IN UCHAR Byte,
|
||||||
IN SIZE_T Length);
|
IN SIZE_T Length);
|
||||||
|
|
||||||
|
XTCDECL
|
||||||
|
SIZE_T
|
||||||
|
RtlStringLength(IN CONST PUCHAR String,
|
||||||
|
IN SIZE_T MaxLength);
|
||||||
|
|
||||||
|
XTCDECL
|
||||||
|
INT
|
||||||
|
RtlStringToWideString(PWCHAR Destination,
|
||||||
|
CONST PUCHAR *Source,
|
||||||
|
SIZE_T Length);
|
||||||
|
|
||||||
XTCDECL
|
XTCDECL
|
||||||
INT
|
INT
|
||||||
RtlWideStringCompare(IN CONST PWCHAR String1,
|
RtlWideStringCompare(IN CONST PWCHAR String1,
|
||||||
|
@ -12,6 +12,7 @@ list(APPEND XTOSKRNL_SOURCE
|
|||||||
${XTOSKRNL_SOURCE_DIR}/ke/krnlinit.c
|
${XTOSKRNL_SOURCE_DIR}/ke/krnlinit.c
|
||||||
${XTOSKRNL_SOURCE_DIR}/rtl/memory.c
|
${XTOSKRNL_SOURCE_DIR}/rtl/memory.c
|
||||||
${XTOSKRNL_SOURCE_DIR}/rtl/plist.c
|
${XTOSKRNL_SOURCE_DIR}/rtl/plist.c
|
||||||
|
${XTOSKRNL_SOURCE_DIR}/rtl/string.c
|
||||||
${XTOSKRNL_SOURCE_DIR}/rtl/widestr.c)
|
${XTOSKRNL_SOURCE_DIR}/rtl/widestr.c)
|
||||||
|
|
||||||
# Set module definition SPEC file
|
# Set module definition SPEC file
|
||||||
|
101
xtoskrnl/rtl/string.c
Normal file
101
xtoskrnl/rtl/string.c
Normal file
@ -0,0 +1,101 @@
|
|||||||
|
/**
|
||||||
|
* PROJECT: ExectOS
|
||||||
|
* COPYRIGHT: See COPYING.md in the top level directory
|
||||||
|
* FILE: xtoskrnl/rtl/string.c
|
||||||
|
* DESCRIPTION: String support
|
||||||
|
* DEVELOPERS: Rafal Kupiec <belliash@codingworkshop.eu.org>
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "xtkmapi.h"
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calculates the length of a given string.
|
||||||
|
*
|
||||||
|
* @param String
|
||||||
|
* Pointer to the null-terminated string to be examined.
|
||||||
|
*
|
||||||
|
* @param MaxLength
|
||||||
|
* Maximum number of characters to examine. If no limit set, it examines whole string.
|
||||||
|
*
|
||||||
|
* @return The length of the null-terminated string.
|
||||||
|
*
|
||||||
|
* @since: XT 1.0
|
||||||
|
*/
|
||||||
|
XTCDECL
|
||||||
|
SIZE_T
|
||||||
|
RtlStringLength(IN CONST PUCHAR String,
|
||||||
|
IN SIZE_T MaxLength)
|
||||||
|
{
|
||||||
|
SIZE_T Length;
|
||||||
|
|
||||||
|
/* Check if NULL pointer passed */
|
||||||
|
if(String == NULL)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Iterate through the wide string */
|
||||||
|
for(Length = 0; ; Length++)
|
||||||
|
{
|
||||||
|
|
||||||
|
/* Check if NULL found or max length limit reached */
|
||||||
|
if((Length != 0 && Length == MaxLength) || !String[Length])
|
||||||
|
{
|
||||||
|
/* Finish examination */
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Return wide string length */
|
||||||
|
return Length;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a multibyte character string to its wide character representation.
|
||||||
|
*
|
||||||
|
* @param Destination
|
||||||
|
* Pointer to wide character array where the wide string will be stored
|
||||||
|
*
|
||||||
|
* @param Source
|
||||||
|
* Pointer to the first element of a multibyte string to convert.
|
||||||
|
*
|
||||||
|
* @param Length
|
||||||
|
* Number of characters in the source string.
|
||||||
|
*
|
||||||
|
* @return Returns the number of wide characters written to the destination array on success, or -1 on error.
|
||||||
|
*
|
||||||
|
* @since XT 1.0
|
||||||
|
*/
|
||||||
|
XTCDECL
|
||||||
|
INT
|
||||||
|
RtlStringToWideString(PWCHAR Destination,
|
||||||
|
CONST PUCHAR *Source,
|
||||||
|
SIZE_T Length)
|
||||||
|
{
|
||||||
|
PUCHAR LocalSource = *Source;
|
||||||
|
SIZE_T Count = Length;
|
||||||
|
|
||||||
|
if(Destination == NULL)
|
||||||
|
{
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
while(Count)
|
||||||
|
{
|
||||||
|
if((*Destination = (UCHAR)*LocalSource) == 0)
|
||||||
|
{
|
||||||
|
LocalSource = NULL;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if(*Destination >= 0x80)
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
LocalSource++;
|
||||||
|
Destination++;
|
||||||
|
Count--;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Length - Count;
|
||||||
|
}
|
@ -6,6 +6,8 @@
|
|||||||
@ stdcall RtlMoveMemory(ptr ptr long)
|
@ stdcall RtlMoveMemory(ptr ptr long)
|
||||||
@ stdcall RtlSameMemory(ptr ptr long)
|
@ stdcall RtlSameMemory(ptr ptr long)
|
||||||
@ stdcall RtlSetMemory(ptr long long)
|
@ stdcall RtlSetMemory(ptr long long)
|
||||||
|
@ cdecl RtlStringLength(str long)
|
||||||
|
@ cdecl RtlStringToWideString(wstr str long)
|
||||||
@ cdecl RtlWideStringCompare(wstr wstr long)
|
@ cdecl RtlWideStringCompare(wstr wstr long)
|
||||||
@ cdecl RtlWideStringConcatenate(wstr wstr long)
|
@ cdecl RtlWideStringConcatenate(wstr wstr long)
|
||||||
@ cdecl RtlWideStringLength(wstr long)
|
@ cdecl RtlWideStringLength(wstr long)
|
||||||
|
Loading…
Reference in New Issue
Block a user