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
--- /dev/null
+/*
+ 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
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,
#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
//
--- /dev/null
+<?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>
--- /dev/null
+/*
+ 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;
+}
--- /dev/null
+<?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>
<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>
#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)
#define GCC_PACKED __attribute__((packed))
#endif//_MSC_VER
-/* rtl.c */
-PWSTR
-xwcschr(
- PWSTR String,
- WCHAR Char
-);
-
#endif /* __MKHIVE_H__ */
/* EOF */
<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>
LocalKeyName = (PWSTR)KeyName;
for (;;)
{
- End = (PWSTR) xwcschr(LocalKeyName, '\\');
+ End = (PWSTR) utf16_wcschr(LocalKeyName, '\\');
if (End)
{
KeyString.Buffer = LocalKeyName;
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 */
#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
*
if(SourceString)
{
- DestSize = xwcslen(SourceString) * sizeof(WCHAR);
+ DestSize = utf16_wcslen(SourceString) * sizeof(WCHAR);
DestinationString->Length = (USHORT)DestSize;
DestinationString->MaximumLength = (USHORT)DestSize + sizeof(WCHAR);
}