mirror of
https://github.com/reactos/reactos.git
synced 2024-09-30 22:47:28 +00:00
Add a library "host_wcsfuncs" with implementations for UTF-16 string functions needed for some host tools
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
This commit is contained in:
parent
33c4221b1e
commit
8d9b815544
24
reactos/include/host/wcsfuncs.h
Normal file
24
reactos/include/host/wcsfuncs.h
Normal file
|
@ -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
|
|
@ -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,
|
||||
|
|
|
@ -23,8 +23,12 @@
|
|||
#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
|
||||
//
|
||||
|
|
7
reactos/lib/host/directory.rbuild
Normal file
7
reactos/lib/host/directory.rbuild
Normal file
|
@ -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>
|
48
reactos/lib/host/wcsfuncs/wcsfuncs.c
Normal file
48
reactos/lib/host/wcsfuncs/wcsfuncs.c
Normal file
|
@ -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;
|
||||
}
|
6
reactos/lib/host/wcsfuncs/wcsfuncs.rbuild
Normal file
6
reactos/lib/host/wcsfuncs/wcsfuncs.rbuild
Normal file
|
@ -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>
|
|
@ -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>
|
||||
|
|
|
@ -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 */
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -127,7 +127,7 @@ RegpOpenOrCreateKey(
|
|||
LocalKeyName = (PWSTR)KeyName;
|
||||
for (;;)
|
||||
{
|
||||
End = (PWSTR) xwcschr(LocalKeyName, '\\');
|
||||
End = (PWSTR) utf16_wcschr(LocalKeyName, '\\');
|
||||
if (End)
|
||||
{
|
||||
KeyString.Buffer = LocalKeyName;
|
||||
|
@ -138,7 +138,7 @@ RegpOpenOrCreateKey(
|
|||
RtlInitUnicodeString(&KeyString, LocalKeyName);
|
||||
|
||||
/* Redirect from 'CurrentControlSet' to 'ControlSet001' */
|
||||
if (!xwcsncmp(LocalKeyName, L"CurrentControlSet", 17) &&
|
||||
if (!utf16_wcsncmp(LocalKeyName, L"CurrentControlSet", 17) &&
|
||||
ParentKey->NameSize == 12 &&
|
||||
!memcmp(ParentKey->Name, L"SYSTEM", 12))
|
||||
RtlInitUnicodeString(&KeyString, L"ControlSet001");
|
||||
|
|
|
@ -10,41 +10,6 @@
|
|||
#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);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue