Various fixes to the existing routines:
ci/woodpecker/push/build Pipeline was successful Details

* Export RtlWideStringTokenize()
 * Allow to compare whole strings in RtlWideStringCompare() when no length specified
 * RtlSameMemory() returns boolean now
 * Source bytes can be constant value in RtlCopyMemory()
This commit is contained in:
Rafal Kupiec 2022-09-05 15:17:12 +02:00
parent 8a91412ec4
commit d56b10f252
Signed by: belliash
GPG Key ID: 4E829243E0CFE6B4
4 changed files with 30 additions and 22 deletions

View File

@ -15,7 +15,7 @@
XTAPI
PVOID
VOID
RtlCopyMemory(IN PVOID Destination,
IN PCVOID Source,
IN SIZE_T Length);
@ -38,16 +38,18 @@ BOOLEAN
RtlListEmpty(PLIST_ENTRY ListHead);
XTAPI
SIZE_T
BOOLEAN
RtlSameMemory(IN PCVOID LeftBuffer,
IN PCVOID RightBuffer,
IN SIZE_T Length);
XTCDECL
INT
RtlWideStringCompare(IN CONST PWCHAR String1,
IN CONST PWCHAR String2,
IN CONST ULONG Length);
XTCDECL
PWCHAR
RtlWideStringTokenize(IN PWCHAR String,
IN CONST PWCHAR Delimiter,

View File

@ -21,27 +21,24 @@
* @param Length
* Specifies the number of bytes to copy.
*
* @return Returns the destination pointer.
* @return This routine does not return any value.
*
* @since NT 3.5
*/
XTAPI
PVOID
VOID
RtlCopyMemory(IN PVOID Destination,
IN PCVOID Source,
IN SIZE_T Length)
{
PCHAR DestinationBytes = (PCHAR)Destination;
PCHAR SourceBytes = (PCHAR)Source;
PCCHAR SourceBytes = (PCHAR)Source;
/* Forward buffer copy */
while(Length--)
{
*DestinationBytes++ = *SourceBytes++;
}
/* Return pointer to destination buffer */
return Destination;
}
/**
@ -56,20 +53,18 @@ RtlCopyMemory(IN PVOID Destination,
* @param Length
* Specifies a number of bytes to compare.
*
* @return A value indicating the relationship between the content of the memory blocks.
* It returns zero (0) if both memory blocks are equal or a value different than
* zero representing which is greater if they do not match.
* @return Returns TRUE if both buffers are equal up to the specified length, or FALSE otherwise.
*
* @since XT 1.0
*/
XTAPI
SIZE_T
BOOLEAN
RtlSameMemory(IN PCVOID LeftBuffer,
IN PCVOID RightBuffer,
IN SIZE_T Length)
{
CONST UCHAR *Left = (PUCHAR)LeftBuffer;
CONST UCHAR *Right = (PUCHAR)RightBuffer;
CONST CHAR *Left = (PCHAR)LeftBuffer;
CONST CHAR *Right = (PCHAR)RightBuffer;
/* Check if there is anything to compare */
if(Length)
@ -81,7 +76,7 @@ RtlSameMemory(IN PCVOID LeftBuffer,
if(*Left != *Right)
{
/* Buffers differ */
return (*Left - *Right);
return FALSE;
}
/* Advance to next byte */
@ -91,5 +86,5 @@ RtlSameMemory(IN PCVOID LeftBuffer,
}
/* Buffers equal */
return 0;
return TRUE;
}

View File

@ -25,6 +25,7 @@
*
* @since XT 1.0
*/
XTCDECL
INT
RtlWideStringCompare(IN CONST PWCHAR String1,
IN CONST PWCHAR String2,
@ -33,7 +34,14 @@ RtlWideStringCompare(IN CONST PWCHAR String1,
ULONG Index;
/* Iterate through the strings */
for(Index = 0; Index < Length; Index++) {
for(Index = 0; ; Index++) {
/* Check if length limit reached */
if(Index != 0 && Index == Length)
{
/* Skip checking next characters */
break;
}
/* Check if string characters are equal */
if(String1[Index] != String2[Index])
{
@ -42,9 +50,9 @@ RtlWideStringCompare(IN CONST PWCHAR String1,
}
/* Check if end of string reached */
if(!String1[Index])
if(!String1[Index] || !String2[Index])
{
/* Equal strings until the end of String1 */
/* Equal strings until the end of one of them */
return 0;
}
}
@ -69,6 +77,7 @@ RtlWideStringCompare(IN CONST PWCHAR String1,
*
* @since: XT 1.0
*/
XTCDECL
PWCHAR
RtlWideStringTokenize(IN PWCHAR String,
IN CONST PWCHAR Delimiter,
@ -81,7 +90,7 @@ RtlWideStringTokenize(IN PWCHAR String,
if(String == NULL && (String = *SavePtr) == NULL)
{
/* Empty string given */
return (NULL);
return NULL;
}
/* Check non-delimiter characters */
@ -89,7 +98,7 @@ RtlWideStringTokenize(IN PWCHAR String,
if(Char == L'\0')
{
*SavePtr = NULL;
return (NULL);
return NULL;
}
Token = String - 1;
@ -110,6 +119,7 @@ RtlWideStringTokenize(IN PWCHAR String,
{
String[-1] = L'\0';
}
/* Store pointer to the next token */
*SavePtr = String;

View File

@ -2,4 +2,5 @@
@ stdcall HlIoPortOutByte(ptr long)
@ stdcall RtlCopyMemory(ptr ptr long)
@ stdcall RtlSameMemory(ptr ptr long)
@ stdcall RtlWideStringCompare(wstr wstr long)
@ stdcall RtlWideStringCompare(wstr wstr long)
@ stdcall RtlWideStringTokenize(wstr wstr wstr)