From a0f359bcf7531f55196d33dc204abf22cc04c955 Mon Sep 17 00:00:00 2001 From: belliash Date: Mon, 26 Sep 2022 17:26:00 +0200 Subject: [PATCH] Implement RtlWideStringConcatenate() routine --- sdk/xtdk/rtlfuncs.h | 6 +++++ xtoskrnl/rtl/widestr.c | 59 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) diff --git a/sdk/xtdk/rtlfuncs.h b/sdk/xtdk/rtlfuncs.h index e74d710..f53c22c 100644 --- a/sdk/xtdk/rtlfuncs.h +++ b/sdk/xtdk/rtlfuncs.h @@ -73,6 +73,12 @@ RtlWideStringCompare(IN CONST PWCHAR String1, IN CONST PWCHAR String2, IN CONST ULONG Length); +XTCDECL +PWCHAR +RtlWideStringConcatenate(PWCHAR Destination, + PWCHAR Source, + SIZE_T Count); + XTCDECL SIZE_T RtlWideStringLength(IN CONST PWCHAR String, diff --git a/xtoskrnl/rtl/widestr.c b/xtoskrnl/rtl/widestr.c index b75b19d..467f4ff 100644 --- a/xtoskrnl/rtl/widestr.c +++ b/xtoskrnl/rtl/widestr.c @@ -61,6 +61,65 @@ RtlWideStringCompare(IN CONST PWCHAR String1, return 0; } +/** + * Appends a copy of the source wide string to the end of the destination wide string. + * + * @param Destination + * Supplies a pointer to the null-terminated wide string to append to. + * + * @param Source + * Supplies a pointer to the null-terminated wide string to copy from. + * + * @param Count + * Sets a maximum number of wide characters to copy. If no limit set, appends whole wide string. + * + * @return This routine returns a copy of a destination wide string. + * + * @since XT 1.0 + */ +XTCDECL +PWCHAR +RtlWideStringConcatenate(PWCHAR Destination, + PWCHAR Source, + SIZE_T Count) +{ + PWCHAR DestString = Destination; + + /* Go to the end of destination wide string */ + while(*Destination) + { + Destination++; + } + + /* Check if copy limit set */ + if(Count > 0) + { + /* Copy character-by-character */ + do + { + /* Check if NULL terminated character found */ + if((*Destination = *Source++) == '\0') + { + /* Break on '\0' character */ + break; + } + Destination++; + } + while(--Count != 0); + + /* Add NULL termination character to the end of destination wide string */ + *Destination = '\0'; + } + else + { + /* No limit set, copy all wide characters */ + while((*Destination++ = *Source++) != 0); + } + + /* Return copy of the destination wide string */ + return DestString; +} + /** * Calculates the length of a given wide string. *