Add a library "host_wcsfuncs" with implementations for UTF-16 string functions needed...
authorColin Finck <colin@reactos.org>
Sun, 22 Jun 2008 20:58:56 +0000 (20:58 +0000)
committerColin Finck <colin@reactos.org>
Sun, 22 Jun 2008 20:58:56 +0000 (20:58 +0000)
Instead of copying those functions into every host tool, which needs it (as we did previously), we can now implement them all in this library and link the host tools to it.
If USE_HOST_WCSFUNCS is not defined, the "wcsfuncs.h" file will define them to the CRT functions (so this library does not create overhead, when the code is built for the target platform)

See issue #3285 for more details.

svn path=/trunk/; revision=34050

reactos/include/host/wcsfuncs.h [new file with mode: 0644]
reactos/lib/cmlib/cminit.c
reactos/lib/cmlib/cmlib.h
reactos/lib/host/directory.rbuild [new file with mode: 0644]
reactos/lib/host/wcsfuncs/wcsfuncs.c [new file with mode: 0644]
reactos/lib/host/wcsfuncs/wcsfuncs.rbuild [new file with mode: 0644]
reactos/lib/lib.rbuild
reactos/tools/mkhive/mkhive.h
reactos/tools/mkhive/mkhive.rbuild
reactos/tools/mkhive/registry.c
reactos/tools/mkhive/rtl.c

diff --git a/reactos/include/host/wcsfuncs.h b/reactos/include/host/wcsfuncs.h
new file mode 100644 (file)
index 0000000..bf2c127
--- /dev/null
@@ -0,0 +1,24 @@
+/*
+  PROJECT:    ReactOS
+  LICENSE:    GPL v2 or any later version
+  FILE:       include/host/wcsfuncs.h
+  PURPOSE:    Header for the "host_wcsfuncs" static library
+  COPYRIGHT:  Copyright 2008 Colin Finck <mail@colinfinck.de>
+*/
+
+#ifndef _HOST_WCSFUNCS_H
+#define _HOST_WCSFUNCS_H
+
+#ifdef USE_HOST_WCSFUNCS
+    /* Function prototypes */
+    SIZE_T utf16_wcslen(PCWSTR str);
+    PWSTR utf16_wcschr(PWSTR str, WCHAR c);
+    INT utf16_wcsncmp(PCWSTR string1, PCWSTR string2, size_t count);
+#else
+    /* Define the utf16_ functions to the CRT functions */
+    #define utf16_wcslen  wcslen
+    #define utf16_wcschr  wcschr
+    #define utf16_wcsncmp wcsncmp
+#endif
+
+#endif
index 816d4d2..7c3f7dd 100644 (file)
@@ -19,7 +19,7 @@ CmCreateRootNode(
    SIZE_T NameSize;
 
    /* Allocate the cell */
-   NameSize = wcslen(Name) * sizeof(WCHAR);
+   NameSize = utf16_wcslen(Name) * sizeof(WCHAR);
    RootCellIndex = HvAllocateCell(Hive,
                                   FIELD_OFFSET(CM_KEY_NODE, Name) + NameSize,
                                   Stable,
index ebcf2ec..66a5ffa 100644 (file)
@@ -9,22 +9,26 @@
 #define CMLIB_H
 
 #ifdef CMLIB_HOST
-#include <host/typedefs.h>
-#include <stdio.h>
-#include <string.h>
-
-// Definitions copied from <ntstatus.h>
-// We only want to include host headers, so we define them manually
-#define STATUS_SUCCESS                   ((NTSTATUS)0x00000000)
-#define STATUS_NOT_IMPLEMENTED           ((NTSTATUS)0xC0000002)
-#define STATUS_NO_MEMORY                 ((NTSTATUS)0xC0000017)
-#define STATUS_INSUFFICIENT_RESOURCES    ((NTSTATUS)0xC000009A)
-#define STATUS_REGISTRY_CORRUPT          ((NTSTATUS)0xC000014C)
-#define STATUS_NOT_REGISTRY_FILE         ((NTSTATUS)0xC000015C)
-#define STATUS_REGISTRY_RECOVERED        ((NTSTATUS)0x40000009)
-
+    #include <host/typedefs.h>
+    #include <stdio.h>
+    #include <string.h>
+
+    // Definitions copied from <ntstatus.h>
+    // We only want to include host headers, so we define them manually
+    #define STATUS_SUCCESS                   ((NTSTATUS)0x00000000)
+    #define STATUS_NOT_IMPLEMENTED           ((NTSTATUS)0xC0000002)
+    #define STATUS_NO_MEMORY                 ((NTSTATUS)0xC0000017)
+    #define STATUS_INSUFFICIENT_RESOURCES    ((NTSTATUS)0xC000009A)
+    #define STATUS_REGISTRY_CORRUPT          ((NTSTATUS)0xC000014C)
+    #define STATUS_NOT_REGISTRY_FILE         ((NTSTATUS)0xC000015C)
+    #define STATUS_REGISTRY_RECOVERED        ((NTSTATUS)0x40000009)
+
+    /* For <host/wcsfuncs.h> */
+    #define USE_HOST_WCSFUNCS
 #endif
 
+#include <host/wcsfuncs.h>
+
 //
 // Debug support switch
 //
diff --git a/reactos/lib/host/directory.rbuild b/reactos/lib/host/directory.rbuild
new file mode 100644 (file)
index 0000000..d39ecfa
--- /dev/null
@@ -0,0 +1,7 @@
+<?xml version="1.0"?>
+<!DOCTYPE group SYSTEM "../../tools/rbuild/project.dtd">
+<group xmlns:xi="http://www.w3.org/2001/XInclude">
+       <directory name="wcsfuncs">
+               <xi:include href="wcsfuncs/wcsfuncs.rbuild" />
+       </directory>
+</group>
diff --git a/reactos/lib/host/wcsfuncs/wcsfuncs.c b/reactos/lib/host/wcsfuncs/wcsfuncs.c
new file mode 100644 (file)
index 0000000..fc40b74
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+  PROJECT:    ReactOS
+  LICENSE:    GPL v2 or any later version
+  FILE:       lib/host/wcsfuncs/wcsfuncs.c
+  PURPOSE:    Reimplemented wide-character string functions for host tools (to be independent of the host wchar_t size)
+  COPYRIGHT:  Copyright 2008 Colin Finck <mail@colinfinck.de>
+*/
+
+#include <host/typedefs.h>
+
+/* Function implementations */
+SIZE_T utf16_wcslen(PCWSTR str)
+{
+    SIZE_T i;
+
+    for(i = 0; str[i]; i++);
+
+    return i;
+}
+
+PWSTR utf16_wcschr(PWSTR str, WCHAR c)
+{
+    SIZE_T i;
+
+    for(i = 0; str[i] && str[i] != c; i++);
+
+    if(str[i])
+        return &str[i];
+    else
+        return NULL;
+}
+
+INT utf16_wcsncmp(PCWSTR string1, PCWSTR string2, size_t count)
+{
+    while(count--)
+    {
+        if(*string1 != *string2)
+            return 1;
+
+        if(*string1 == 0)
+            return 0;
+
+        string1++;
+        string2++;
+    }
+
+    return 0;
+}
diff --git a/reactos/lib/host/wcsfuncs/wcsfuncs.rbuild b/reactos/lib/host/wcsfuncs/wcsfuncs.rbuild
new file mode 100644 (file)
index 0000000..d955a30
--- /dev/null
@@ -0,0 +1,6 @@
+<?xml version="1.0"?>
+<!DOCTYPE module SYSTEM "../../../tools/rbuild/project.dtd">
+<module name="host_wcsfuncs" type="staticlibrary">
+       <include base="ReactOS">include</include>
+       <file>wcsfuncs.c</file>
+</module>
index 9048bc4..fdc8fc5 100644 (file)
@@ -22,6 +22,9 @@
        <directory name="fslib">
                <xi:include href="fslib/directory.rbuild" />
        </directory>
+       <directory name="host">
+               <xi:include href="host/directory.rbuild" />
+       </directory>
        <directory name="inflib">
                <xi:include href="inflib/inflib.rbuild" />
        </directory>
index e683ee9..237bfa4 100644 (file)
@@ -32,6 +32,9 @@
 
 #include <host/typedefs.h>
 
+#define USE_HOST_WCSFUNCS
+#include <host/wcsfuncs.h>
+
 // Definitions copied from <ntstatus.h>
 // We only want to include host headers, so we define them manually
 #define STATUS_SUCCESS                   ((NTSTATUS)0x00000000)
@@ -96,13 +99,6 @@ extern LIST_ENTRY CmiHiveListHead;
 #define GCC_PACKED __attribute__((packed))
 #endif//_MSC_VER
 
-/* rtl.c */
-PWSTR
-xwcschr(
-   PWSTR String,
-   WCHAR Char
-);
-
 #endif /* __MKHIVE_H__ */
 
 /* EOF */
index e3d7506..0eed6bf 100644 (file)
@@ -11,6 +11,7 @@
        <compilerflag>-fshort-wchar</compilerflag>
        <library>inflibhost</library>
        <library>cmlibhost</library>
+       <library>host_wcsfuncs</library>
        <file>binhive.c</file>
        <file>cmi.c</file>
        <file>mkhive.c</file>
index 4b1492c..1a70bdf 100644 (file)
@@ -127,7 +127,7 @@ RegpOpenOrCreateKey(
        LocalKeyName = (PWSTR)KeyName;
        for (;;)
        {
-               End = (PWSTR) xwcschr(LocalKeyName, '\\');
+               End = (PWSTR) utf16_wcschr(LocalKeyName, '\\');
                if (End)
                {
                        KeyString.Buffer = LocalKeyName;
@@ -138,9 +138,9 @@ RegpOpenOrCreateKey(
                        RtlInitUnicodeString(&KeyString, LocalKeyName);
 
                /* Redirect from 'CurrentControlSet' to 'ControlSet001' */
-               if (!xwcsncmp(LocalKeyName, L"CurrentControlSet", 17) &&
-                    ParentKey->NameSize == 12 &&
-                    !memcmp(ParentKey->Name, L"SYSTEM", 12))
+               if (!utf16_wcsncmp(LocalKeyName, L"CurrentControlSet", 17) &&
+                           ParentKey->NameSize == 12 &&
+                           !memcmp(ParentKey->Name, L"SYSTEM", 12))
                        RtlInitUnicodeString(&KeyString, L"ControlSet001");
 
                /* Check subkey in memory structure */
index 1ccb8ac..eec2fc3 100644 (file)
 #include "mkhive.h"
 #include <bitmap.c>
 
-SIZE_T xwcslen( PCWSTR String ) {
-       SIZE_T i;
-
-       for( i = 0; String[i]; i++ );
-
-       return i;
-}
-
-PWSTR xwcschr( PWSTR String, WCHAR Char )
-{
-       SIZE_T i;
-
-       for( i = 0; String[i] && String[i] != Char; i++ );
-
-       if( String[i] ) return &String[i];
-       else return NULL;
-}
-
-int xwcsncmp(PCWSTR s1, PCWSTR s2, size_t n)
-{
-    while(n--)
-    {
-        if(*s1 != *s2)
-            return 1;
-
-        if(*s1 == 0)
-            return 0;
-
-        s1++;
-        s2++;
-    }
-
-    return 0;
-}
-
 /*
  * @implemented
  *
@@ -88,7 +53,7 @@ RtlInitUnicodeString(
 
        if(SourceString)
        {
-               DestSize = xwcslen(SourceString) * sizeof(WCHAR);
+               DestSize = utf16_wcslen(SourceString) * sizeof(WCHAR);
                DestinationString->Length = (USHORT)DestSize;
                DestinationString->MaximumLength = (USHORT)DestSize + sizeof(WCHAR);
        }