Split out the resource functions for finer control of debug output.

svn path=/trunk/; revision=3832
This commit is contained in:
Robert Dickenson 2002-12-08 15:57:40 +00:00
parent 688e9b05d9
commit 61bb7ba7ad
9 changed files with 1407 additions and 1194 deletions

269
reactos/lib/ntdll/ldr/res.c Normal file
View file

@ -0,0 +1,269 @@
/* $Id: res.c,v 1.1 2002/12/08 15:57:40 robd Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* FILE: lib/ntdll/ldr/res.c
* PURPOSE: Resource access for PE executables
* PROGRAMMERS: Jean Michault
* Rex Jolliff (rex@lvcablemodem.com)
* Robert Dickenson (robd@mok.lvcm.com)
*/
/*
* TODO:
* - any comments ??
*/
/* INCLUDES *****************************************************************/
#include <reactos/config.h>
#include <ddk/ntddk.h>
#include <windows.h>
#include <string.h>
#include <wchar.h>
#include <ntdll/ldr.h>
#include <ntos/minmax.h>
//#define NDEBUG
#define DBG
#include <ntdll/ntdll.h>
/* PROTOTYPES ****************************************************************/
/* FUNCTIONS *****************************************************************/
/*
Status = LdrFindResource_U (hModule,
&ResourceInfo,
RESOURCE_DATA_LEVEL,
&ResourceDataEntry);
*/
NTSTATUS STDCALL
LdrFindResource_U(PVOID BaseAddress,
PLDR_RESOURCE_INFO ResourceInfo,
ULONG Level,
PIMAGE_RESOURCE_DATA_ENTRY* ResourceDataEntry)
{
PIMAGE_RESOURCE_DIRECTORY ResDir;
PIMAGE_RESOURCE_DIRECTORY ResBase;
PIMAGE_RESOURCE_DIRECTORY_ENTRY ResEntry;
NTSTATUS Status = STATUS_SUCCESS;
ULONG EntryCount;
PWCHAR ws;
ULONG i;
ULONG Id;
//DPRINT("LdrFindResource_U()\n");
DPRINT("LdrFindResource_U(%08x, %08x, %d, %08x)\n", BaseAddress, ResourceInfo, Level, ResourceDataEntry);
/* Get the pointer to the resource directory */
ResDir = (PIMAGE_RESOURCE_DIRECTORY)RtlImageDirectoryEntryToData(BaseAddress,
TRUE, IMAGE_DIRECTORY_ENTRY_RESOURCE, &i);
if (ResDir == NULL) {
return STATUS_RESOURCE_DATA_NOT_FOUND;
}
DPRINT("ResourceDirectory: %x Size: %d\n", (ULONG)ResDir, (int)i);
ResBase = ResDir;
/* Let's go into resource tree */
for (i = 0; i < Level; i++) {
DPRINT("ResDir: %x Level: %d\n", (ULONG)ResDir, i);
Id = ((PULONG)ResourceInfo)[i];
// ResourceInfo.Type = (ULONG)lpType;
// ResourceInfo.Name = (ULONG)lpName;
// ResourceInfo.Language = (ULONG)wLanguage;
EntryCount = ResDir->NumberOfNamedEntries;
DPRINT(" Id: %d NumberOfNamedEntries: %d\n", Id, EntryCount);
ResEntry = (PIMAGE_RESOURCE_DIRECTORY_ENTRY)(ResDir + 1);
//DPRINT("ResEntry %x\n", (ULONG)ResEntry);
if (Id & 0xFFFF0000) {
/* Resource name is a unicode string */
DPRINT("ResEntry %x - Resource name is a unicode string\n", (ULONG)ResEntry);
DPRINT("EntryCount %d\n", (ULONG)EntryCount);
for (; EntryCount--; ResEntry++) {
/* Scan entries for equal name */
if (ResEntry->Name & 0x80000000) {
ws = (PWCHAR)((ULONG)ResDir + (ResEntry->Name & 0x7FFFFFFF));
if (!wcsncmp((PWCHAR)Id, ws + 1, *ws) &&
wcslen((PWCHAR)Id) == (int)*ws) {
goto found;
}
}
}
} else {
/* We use ID number instead of string */
DPRINT("ResEntry %x - Resource ID number instead of string\n", (ULONG)ResEntry);
DPRINT("EntryCount %d\n", (ULONG)EntryCount);
ResEntry += EntryCount;
EntryCount = ResDir->NumberOfIdEntries;
DPRINT("EntryCount %d\n", (ULONG)EntryCount);
for (; EntryCount--; ResEntry++) {
/* Scan entries for equal name */
DPRINT("EntryCount %d ResEntry %x\n", (ULONG)EntryCount, ResEntry);
DPRINT("ResEntry->Name %x Id %x\n", (ULONG)ResEntry->Name, Id);
if (ResEntry->Name == Id) {
DPRINT("ID entry found %x\n", Id);
goto found;
}
}
}
//DPRINT("Error %lu\n", i);
switch (i) {
case 0:
DPRINT("Error %lu - STATUS_RESOURCE_TYPE_NOT_FOUND\n", i);
return STATUS_RESOURCE_TYPE_NOT_FOUND;
case 1:
DPRINT("Error %lu - STATUS_RESOURCE_NAME_NOT_FOUND\n", i);
return STATUS_RESOURCE_NAME_NOT_FOUND;
case 2:
if (ResDir->NumberOfNamedEntries || ResDir->NumberOfIdEntries) {
/* Use the first available language */
ResEntry = (IMAGE_RESOURCE_DIRECTORY_ENTRY*)(ResDir + 1);
break;
}
DPRINT("Error %lu - STATUS_RESOURCE_LANG_NOT_FOUND\n", i);
return STATUS_RESOURCE_LANG_NOT_FOUND;
case 3:
DPRINT("Error %lu - STATUS_RESOURCE_DATA_NOT_FOUND\n", i);
return STATUS_RESOURCE_DATA_NOT_FOUND;
default:
DPRINT("Error %lu - STATUS_INVALID_PARAMETER\n", i);
return STATUS_INVALID_PARAMETER;
}
found:;
ResDir = (PIMAGE_RESOURCE_DIRECTORY)((ULONG)ResBase +
(ResEntry->OffsetToData & 0x7FFFFFFF));
}
DPRINT("ResourceDataEntry: %x\n", (ULONG)ResDir);
if (ResourceDataEntry) {
*ResourceDataEntry = (PVOID)ResDir;
}
return Status;
}
NTSTATUS STDCALL
LdrAccessResource(IN PVOID BaseAddress,
IN PIMAGE_RESOURCE_DATA_ENTRY ResourceDataEntry,
OUT PVOID* Resource OPTIONAL,
OUT PULONG Size OPTIONAL)
{
PIMAGE_SECTION_HEADER Section;
PIMAGE_NT_HEADERS NtHeader;
ULONG SectionRva;
ULONG SectionVa;
ULONG DataSize;
ULONG Offset = 0;
ULONG Data;
Data = (ULONG)RtlImageDirectoryEntryToData(BaseAddress,
TRUE, IMAGE_DIRECTORY_ENTRY_RESOURCE, &DataSize);
if (Data == 0) {
return STATUS_RESOURCE_DATA_NOT_FOUND;
}
if ((ULONG)BaseAddress & 1) {
/* loaded as ordinary file */
NtHeader = RtlImageNtHeader((PVOID)((ULONG)BaseAddress & ~1UL));
Offset = (ULONG)BaseAddress - Data + NtHeader->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_RESOURCE].VirtualAddress;
Section = RtlImageRvaToSection(NtHeader, BaseAddress, NtHeader->OptionalHeader.DataDirectory[IMAGE_DIRECTORY_ENTRY_RESOURCE].VirtualAddress);
if (Section == NULL) {
return STATUS_RESOURCE_DATA_NOT_FOUND;
}
if (Section->Misc.VirtualSize < ResourceDataEntry->OffsetToData) {
SectionRva = RtlImageRvaToSection (NtHeader, BaseAddress, ResourceDataEntry->OffsetToData)->VirtualAddress;
SectionVa = RtlImageRvaToVa(NtHeader, BaseAddress, SectionRva, NULL);
Offset = SectionRva - SectionVa + Data - Section->VirtualAddress;
}
}
if (Resource) {
*Resource = (PVOID)(ResourceDataEntry->OffsetToData - Offset + (ULONG)BaseAddress);
}
if (Size) {
*Size = ResourceDataEntry->Size;
}
return STATUS_SUCCESS;
}
NTSTATUS STDCALL
LdrFindResourceDirectory_U(IN PVOID BaseAddress,
WCHAR** name,
DWORD level,
OUT PVOID* addr)
{
PIMAGE_RESOURCE_DIRECTORY ResDir;
PIMAGE_RESOURCE_DIRECTORY_ENTRY ResEntry;
ULONG EntryCount;
ULONG i;
NTSTATUS Status = STATUS_SUCCESS;
WCHAR* ws;
/* Get the pointer to the resource directory */
ResDir = (PIMAGE_RESOURCE_DIRECTORY)
RtlImageDirectoryEntryToData(BaseAddress, TRUE, IMAGE_DIRECTORY_ENTRY_RESOURCE, &i);
if (ResDir == NULL) {
return STATUS_RESOURCE_DATA_NOT_FOUND;
}
/* Let's go into resource tree */
for (i = 0; i < level; i++, name++) {
EntryCount = ResDir->NumberOfNamedEntries;
ResEntry = (PIMAGE_RESOURCE_DIRECTORY_ENTRY)(ResDir + 1);
if ((ULONG)(*name) & 0xFFFF0000) {
/* Resource name is a unicode string */
for (; EntryCount--; ResEntry++) {
/* Scan entries for equal name */
if (ResEntry->Name & 0x80000000) {
ws = (WCHAR*)((ULONG)ResDir + (ResEntry->Name & 0x7FFFFFFF));
if (!wcsncmp(*name, ws + 1, *ws) && wcslen(*name) == (int)*ws) {
goto found;
}
}
}
} else {
/* We use ID number instead of string */
ResEntry += EntryCount;
EntryCount = ResDir->NumberOfIdEntries;
for (; EntryCount--; ResEntry++) {
/* Scan entries for equal name */
if (ResEntry->Name == (ULONG)(*name))
goto found;
}
}
switch (i) {
case 0:
return STATUS_RESOURCE_TYPE_NOT_FOUND;
case 1:
return STATUS_RESOURCE_NAME_NOT_FOUND;
case 2:
Status = STATUS_RESOURCE_LANG_NOT_FOUND;
/* Just use first language entry */
if (ResDir->NumberOfNamedEntries || ResDir->NumberOfIdEntries) {
ResEntry = (IMAGE_RESOURCE_DIRECTORY_ENTRY*)(ResDir + 1);
break;
}
return Status;
case 3:
return STATUS_RESOURCE_DATA_NOT_FOUND;
default:
return STATUS_INVALID_PARAMETER;
}
found:;
ResDir = (PIMAGE_RESOURCE_DIRECTORY)((ULONG)ResDir + ResEntry->OffsetToData);
}
if (addr) {
*addr = (PVOID)ResDir;
}
return Status;
}
/* EOF */

View file

@ -1,4 +1,4 @@
/* $Id: startup.c,v 1.46 2002/11/15 22:06:01 ekohl Exp $
/* $Id: startup.c,v 1.47 2002/12/08 15:57:40 robd Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel

View file

@ -1,8 +1,8 @@
/* $Id: utils.c,v 1.57 2002/10/01 19:27:20 chorns Exp $
/* $Id: utils.c,v 1.58 2002/12/08 15:57:40 robd Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
* FILE: lib/ntdll/ldr/startup.c
* FILE: lib/ntdll/ldr/utils.c
* PURPOSE: Process startup for PE executables
* PROGRAMMERS: Jean Michault
* Rex Jolliff (rex@lvcablemodem.com)
@ -136,8 +136,7 @@ LdrAdjustDllName (PUNICODE_STRING FullDllName,
memmove (Buffer + Length, L".dll", 10);
}
RtlCreateUnicodeString (FullDllName,
Buffer);
RtlCreateUnicodeString(FullDllName, Buffer);
}
PLDR_MODULE
@ -145,9 +144,7 @@ LdrAddModuleEntry(PVOID ImageBase, PIMAGE_NT_HEADERS NTHeaders,
PWSTR FullDosName)
{
PLDR_MODULE Module;
Module = RtlAllocateHeap(RtlGetProcessHeap(),
0,
sizeof (LDR_MODULE));
Module = RtlAllocateHeap(RtlGetProcessHeap(), 0, sizeof (LDR_MODULE));
assert(Module);
Module->BaseAddress = (PVOID)ImageBase;
Module->EntryPoint = NTHeaders->OptionalHeader.AddressOfEntryPoint;
@ -158,9 +155,7 @@ LdrAddModuleEntry(PVOID ImageBase, PIMAGE_NT_HEADERS NTHeaders,
{
/* loading while app is running */
Module->LoadCount = 1;
}
else
{
} else {
/*
* loading while app is initializing
* dll must not be unloaded
@ -384,8 +379,7 @@ LdrLoadDll (IN PWSTR SearchPath OPTIONAL,
PAGE_READWRITE);
if (!NT_SUCCESS(Status))
{
DbgPrint("NTDLL.LDR: map view of section failed (Status %x)\n",
Status);
DbgPrint("NTDLL.LDR: map view of section failed (Status %x)\n", Status);
ZwClose(FileHandle);
return(Status);
}
@ -1301,6 +1295,7 @@ LdrUnloadDll (IN PVOID BaseAddress)
return STATUS_UNSUCCESSFUL;
}
#if 0 /*MOVED_TO_FILE_RES_C*/
NTSTATUS STDCALL
LdrFindResource_U(PVOID BaseAddress,
@ -1467,47 +1462,39 @@ LdrAccessResource(IN PVOID BaseAddress,
return STATUS_SUCCESS;
}
#endif /*MOVED_TO_FILE_RES_C*/
NTSTATUS STDCALL
LdrDisableThreadCalloutsForDll (IN PVOID BaseAddress)
LdrDisableThreadCalloutsForDll(IN PVOID BaseAddress)
{
PLIST_ENTRY ModuleListHead;
PLIST_ENTRY Entry;
PLDR_MODULE Module;
NTSTATUS Status;
DPRINT("LdrDisableThreadCalloutsForDll (BaseAddress %x)\n",
BaseAddress);
DPRINT("LdrDisableThreadCalloutsForDll (BaseAddress %x)\n", BaseAddress);
Status = STATUS_DLL_NOT_FOUND;
ModuleListHead = &NtCurrentPeb()->Ldr->InLoadOrderModuleList;
Entry = ModuleListHead->Flink;
while (Entry != ModuleListHead)
{
while (Entry != ModuleListHead) {
Module = CONTAINING_RECORD(Entry, LDR_MODULE, InLoadOrderModuleList);
DPRINT("BaseDllName %wZ BaseAddress %x\n",
&Module->BaseDllName,
Module->BaseAddress);
DPRINT("BaseDllName %wZ BaseAddress %x\n", &Module->BaseDllName, Module->BaseAddress);
if (Module->BaseAddress == BaseAddress)
{
if (Module->TlsIndex == 0)
{
if (Module->BaseAddress == BaseAddress) {
if (Module->TlsIndex == 0) {
Module->Flags |= 0x00040000;
Status = STATUS_SUCCESS;
}
return Status;
}
Entry = Entry->Flink;
}
return Status;
}
#if 0 /*MOVED_TO_FILE_RES_C*/
NTSTATUS STDCALL
LdrFindResourceDirectory_U (IN PVOID BaseAddress,
@ -1603,12 +1590,14 @@ found:;
return Status;
}
#endif /*MOVED_TO_FILE_RES_C*/
NTSTATUS STDCALL
LdrGetDllHandle (IN ULONG Unknown1,
NTSTATUS
STDCALL
LdrGetDllHandle(IN ULONG Unknown1,
IN ULONG Unknown2,
IN PUNICODE_STRING DllName,
OUT PVOID *BaseAddress)
OUT PVOID* BaseAddress)
{
UNICODE_STRING FullDllName;
PLIST_ENTRY ModuleListHead;
@ -1619,45 +1608,35 @@ LdrGetDllHandle (IN ULONG Unknown1,
Unknown1, Unknown2, DllName, BaseAddress);
/* NULL is the current executable */
if ( DllName == NULL )
{
if (DllName == NULL) {
*BaseAddress = NtCurrentPeb()->ImageBaseAddress;
DPRINT("BaseAddress %x\n", *BaseAddress);
return STATUS_SUCCESS;
}
LdrAdjustDllName(&FullDllName, DllName, TRUE);
LdrAdjustDllName (&FullDllName,
DllName,
TRUE);
DPRINT("FullDllName %wZ\n",
&FullDllName);
DPRINT("FullDllName %wZ\n", &FullDllName);
ModuleListHead = &NtCurrentPeb()->Ldr->InLoadOrderModuleList;
Entry = ModuleListHead->Flink;
while (Entry != ModuleListHead)
{
while (Entry != ModuleListHead) {
Module = CONTAINING_RECORD(Entry, LDR_MODULE, InLoadOrderModuleList);
DPRINT("EntryPoint %x\n", Module->EntryPoint);
DPRINT("Comparing %wZ and %wZ\n",
&Module->BaseDllName,
&FullDllName);
DPRINT("Comparing %wZ and %wZ\n", &Module->BaseDllName, &FullDllName);
if (!RtlCompareUnicodeString(&Module->BaseDllName, &FullDllName, TRUE))
{
RtlFreeUnicodeString (&FullDllName);
if (!RtlCompareUnicodeString(&Module->BaseDllName, &FullDllName, TRUE)) {
RtlFreeUnicodeString(&FullDllName);
*BaseAddress = Module->BaseAddress;
DPRINT("BaseAddress %x\n", *BaseAddress);
return STATUS_SUCCESS;
}
Entry = Entry->Flink;
}
DPRINT("Failed to find dll %wZ\n", &FullDllName);
RtlFreeUnicodeString (&FullDllName);
RtlFreeUnicodeString(&FullDllName);
*BaseAddress = NULL;
return STATUS_DLL_NOT_FOUND;
}

View file

@ -1,4 +1,4 @@
# $Id: makefile,v 1.75 2002/10/26 00:32:18 chorns Exp $
# $Id: makefile,v 1.76 2002/12/08 15:57:39 robd Exp $
PATH_TO_TOP = ../..
@ -68,6 +68,7 @@ TARGET_OBJECTS = \
$(STDLIB_OBJECTS) \
$(STRING_OBJECTS) \
stubs/stubs.o \
ldr/res.o \
ldr/utils.o \
$(CSR_OBJECTS)

View file

@ -1,4 +1,4 @@
/* $Id: error.c,v 1.11 2002/09/08 10:23:05 chorns Exp $
/* $Id: error.c,v 1.12 2002/12/08 15:57:38 robd Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -826,12 +826,10 @@ RPC_NT_SS_CONTEXT_MISMATCH ERROR_INVALID_HANDLE
VOID
STDCALL
RtlAssert (
PVOID FailedAssertion,
RtlAssert(PVOID FailedAssertion,
PVOID FileName,
ULONG LineNumber,
PCHAR Message
)
PCHAR Message)
{
DbgPrint ("Assertion \'%s\' failed at %s line %d: %s\n",
(PCHAR)FailedAssertion,

View file

@ -1,4 +1,4 @@
/* $Id: largeint.c,v 1.9 2002/09/08 10:23:05 chorns Exp $
/* $Id: largeint.c,v 1.10 2002/12/08 15:57:39 robd Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -121,11 +121,9 @@ RtlExtendedLargeIntegerDivide (
LARGE_INTEGER
STDCALL
RtlExtendedMagicDivide (
LARGE_INTEGER Dividend,
RtlExtendedMagicDivide(LARGE_INTEGER Dividend,
LARGE_INTEGER MagicDivisor,
CCHAR ShiftCount
)
CCHAR ShiftCount)
{
UNIMPLEMENTED;
}

View file

@ -1,4 +1,4 @@
/* $Id: mem.c,v 1.11 2002/09/08 10:23:05 chorns Exp $
/* $Id: mem.c,v 1.12 2002/12/08 15:57:39 robd Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -18,7 +18,9 @@
ULONG
STDCALL
RtlCompareMemory(PVOID Source1, PVOID Source2, ULONG Length)
RtlCompareMemory(PVOID Source1,
PVOID Source2,
ULONG Length)
/*
* FUNCTION: Compares blocks of memory and returns the number of equal bytes
* ARGUMENTS:
@ -95,11 +97,7 @@ RtlFillMemory (
UCHAR Fill
)
{
memset (
Destination,
Fill,
Length
);
memset(Destination, Fill, Length);
}
VOID
@ -122,21 +120,6 @@ RtlFillMemoryUlong (
}
VOID
STDCALL
RtlZeroMemory (
PVOID Destination,
ULONG Length
)
{
RtlFillMemory (
Destination,
Length,
0
);
}
VOID
STDCALL
RtlMoveMemory (
@ -153,4 +136,19 @@ RtlMoveMemory (
}
VOID
STDCALL
RtlZeroMemory (
PVOID Destination,
ULONG Length
)
{
RtlFillMemory (
Destination,
Length,
0
);
}
/* EOF */

View file

@ -1,4 +1,4 @@
/* $Id: time.c,v 1.13 2002/09/30 20:57:54 hbirr Exp $
/* $Id: time.c,v 1.14 2002/12/08 15:57:39 robd Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -55,42 +55,10 @@ static __inline void NormalizeTimeFields(CSHORT *FieldToNormalize,
/* FUNCTIONS *****************************************************************/
VOID STDCALL
RtlTimeToElapsedTimeFields(IN PLARGE_INTEGER Time,
OUT PTIME_FIELDS TimeFields)
{
ULONGLONG ElapsedSeconds;
ULONG SecondsInDay;
ULONG SecondsInMinute;
/* Extract millisecond from time */
TimeFields->Milliseconds = (CSHORT)((Time->QuadPart % TICKSPERSEC) / TICKSPERMSEC);
/* Compute elapsed seconds */
ElapsedSeconds = (ULONGLONG)Time->QuadPart / TICKSPERSEC;
/* Compute seconds within the day */
SecondsInDay = ElapsedSeconds % SECSPERDAY;
/* Compute elapsed minutes within the day */
SecondsInMinute = SecondsInDay % SECSPERHOUR;
/* Compute elapsed time of day */
TimeFields->Hour = (CSHORT)(SecondsInDay / SECSPERHOUR);
TimeFields->Minute = (CSHORT)(SecondsInMinute / SECSPERMIN);
TimeFields->Second = (CSHORT)(SecondsInMinute % SECSPERMIN);
/* Compute elapsed days */
TimeFields->Day = (CSHORT)(ElapsedSeconds / SECSPERDAY);
/* The elapsed number of months and days cannot be calculated */
TimeFields->Month = 0;
TimeFields->Year = 0;
}
VOID STDCALL
RtlTimeToTimeFields(PLARGE_INTEGER liTime,
VOID
STDCALL
RtlTimeToTimeFields(
PLARGE_INTEGER liTime,
PTIME_FIELDS TimeFields)
{
const int *Months;
@ -169,11 +137,14 @@ RtlTimeToTimeFields(PLARGE_INTEGER liTime,
}
BOOLEAN STDCALL
RtlTimeFieldsToTime(PTIME_FIELDS tfTimeFields,
BOOLEAN
STDCALL
RtlTimeFieldsToTime(
PTIME_FIELDS tfTimeFields,
PLARGE_INTEGER Time)
{
int CurYear, CurMonth;
int CurYear;
int CurMonth;
long long int rcTime;
TIME_FIELDS TimeFields = *tfTimeFields;
@ -233,8 +204,10 @@ RtlTimeFieldsToTime(PTIME_FIELDS tfTimeFields,
}
VOID STDCALL
RtlSecondsSince1970ToTime(ULONG SecondsSince1970,
VOID
STDCALL
RtlSecondsSince1970ToTime(
ULONG SecondsSince1970,
PLARGE_INTEGER Time)
{
LONGLONG llTime;
@ -245,8 +218,10 @@ RtlSecondsSince1970ToTime(ULONG SecondsSince1970,
}
VOID STDCALL
RtlSecondsSince1980ToTime(ULONG SecondsSince1980,
VOID
STDCALL
RtlSecondsSince1980ToTime(
ULONG SecondsSince1980,
PLARGE_INTEGER Time)
{
LONGLONG llTime;
@ -257,8 +232,10 @@ RtlSecondsSince1980ToTime(ULONG SecondsSince1980,
}
BOOLEAN STDCALL
RtlTimeToSecondsSince1970(PLARGE_INTEGER Time,
BOOLEAN
STDCALL
RtlTimeToSecondsSince1970(
PLARGE_INTEGER Time,
PULONG SecondsSince1970)
{
LARGE_INTEGER liTime;
@ -267,16 +244,18 @@ RtlTimeToSecondsSince1970(PLARGE_INTEGER Time,
liTime.QuadPart = liTime.QuadPart / TICKSPERSEC;
if (liTime.u.HighPart != 0)
return(FALSE);
return FALSE;
*SecondsSince1970 = liTime.u.LowPart;
return(TRUE);
return TRUE;
}
BOOLEAN STDCALL
RtlTimeToSecondsSince1980(PLARGE_INTEGER Time,
BOOLEAN
STDCALL
RtlTimeToSecondsSince1980(
PLARGE_INTEGER Time,
PULONG SecondsSince1980)
{
LARGE_INTEGER liTime;
@ -285,15 +264,16 @@ RtlTimeToSecondsSince1980(PLARGE_INTEGER Time,
liTime.QuadPart = liTime.QuadPart / TICKSPERSEC;
if (liTime.u.HighPart != 0)
return(FALSE);
return FALSE;
*SecondsSince1980 = liTime.u.LowPart;
return(TRUE);
return TRUE;
}
NTSTATUS STDCALL
NTSTATUS
STDCALL
RtlLocalTimeToSystemTime(PLARGE_INTEGER LocalTime,
PLARGE_INTEGER SystemTime)
{
@ -314,7 +294,8 @@ RtlLocalTimeToSystemTime(PLARGE_INTEGER LocalTime,
}
NTSTATUS STDCALL
NTSTATUS
STDCALL
RtlSystemTimeToLocalTime(PLARGE_INTEGER SystemTime,
PLARGE_INTEGER LocalTime)
{
@ -334,4 +315,40 @@ RtlSystemTimeToLocalTime(PLARGE_INTEGER SystemTime,
return(STATUS_SUCCESS);
}
VOID
STDCALL
RtlTimeToElapsedTimeFields(IN PLARGE_INTEGER Time,
OUT PTIME_FIELDS TimeFields)
{
ULONGLONG ElapsedSeconds;
ULONG SecondsInDay;
ULONG SecondsInMinute;
/* Extract millisecond from time */
TimeFields->Milliseconds = (CSHORT)((Time->QuadPart % TICKSPERSEC) / TICKSPERMSEC);
/* Compute elapsed seconds */
ElapsedSeconds = (ULONGLONG)Time->QuadPart / TICKSPERSEC;
/* Compute seconds within the day */
SecondsInDay = ElapsedSeconds % SECSPERDAY;
/* Compute elapsed minutes within the day */
SecondsInMinute = SecondsInDay % SECSPERHOUR;
/* Compute elapsed time of day */
TimeFields->Hour = (CSHORT)(SecondsInDay / SECSPERHOUR);
TimeFields->Minute = (CSHORT)(SecondsInMinute / SECSPERMIN);
TimeFields->Second = (CSHORT)(SecondsInMinute % SECSPERMIN);
/* Compute elapsed days */
TimeFields->Day = (CSHORT)(ElapsedSeconds / SECSPERDAY);
/* The elapsed number of months and days cannot be calculated */
TimeFields->Month = 0;
TimeFields->Year = 0;
}
/* EOF */

View file

@ -1,4 +1,4 @@
/* $Id: unicode.c,v 1.24 2002/10/20 03:34:00 robd Exp $
/* $Id: unicode.c,v 1.25 2002/12/08 15:57:39 robd Exp $
*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS kernel
@ -21,9 +21,8 @@
WCHAR
STDCALL
RtlAnsiCharToUnicodeChar (
IN CHAR AnsiChar
)
RtlAnsiCharToUnicodeChar(
IN CHAR AnsiChar)
{
ULONG Size;
WCHAR UnicodeChar;
@ -45,9 +44,8 @@ RtlAnsiCharToUnicodeChar (
ULONG
STDCALL
RtlAnsiStringToUnicodeSize (
IN PANSI_STRING AnsiString
)
RtlAnsiStringToUnicodeSize(
IN PANSI_STRING AnsiString)
{
ULONG Size;
@ -64,8 +62,7 @@ STDCALL
RtlAnsiStringToUnicodeString(
IN OUT PUNICODE_STRING DestinationString,
IN PANSI_STRING SourceString,
IN BOOLEAN AllocateDestinationString
)
IN BOOLEAN AllocateDestinationString)
{
NTSTATUS Status;
ULONG Length;
@ -125,10 +122,9 @@ RtlAnsiStringToUnicodeString(
NTSTATUS
STDCALL
RtlAppendAsciizToString (
RtlAppendAsciizToString(
IN OUT PSTRING Destination,
IN PCSZ Source
)
IN PCSZ Source)
{
ULONG Length;
PCHAR Ptr;
@ -155,10 +151,9 @@ RtlAppendAsciizToString (
NTSTATUS
STDCALL
RtlAppendStringToString (
RtlAppendStringToString(
IN OUT PSTRING Destination,
IN PSTRING Source
)
IN PSTRING Source)
{
PCHAR Ptr;
@ -183,10 +178,9 @@ RtlAppendStringToString (
NTSTATUS
STDCALL
RtlAppendUnicodeStringToString (
RtlAppendUnicodeStringToString(
IN OUT PUNICODE_STRING Destination,
IN PUNICODE_STRING Source
)
IN PUNICODE_STRING Source)
{
PWCHAR Src;
PWCHAR Dest;
@ -244,7 +238,7 @@ RtlAppendUnicodeToString(IN OUT PUNICODE_STRING Destination,
NTSTATUS
STDCALL
RtlCharToInteger (
RtlCharToInteger(
IN PCSZ String,
IN ULONG Base,
IN OUT PULONG Value)
@ -285,11 +279,10 @@ RtlCharToInteger (
LONG
STDCALL
RtlCompareString (
RtlCompareString(
IN PSTRING String1,
IN PSTRING String2,
IN BOOLEAN CaseInsensitive
)
IN BOOLEAN CaseInsensitive)
{
ULONG len1, len2;
PCHAR s1, s2;
@ -333,11 +326,10 @@ RtlCompareString (
LONG
STDCALL
RtlCompareUnicodeString (
RtlCompareUnicodeString(
IN PUNICODE_STRING String1,
IN PUNICODE_STRING String2,
IN BOOLEAN CaseInsensitive
)
IN BOOLEAN CaseInsensitive)
{
ULONG len1, len2;
PWCHAR s1, s2;
@ -381,10 +373,9 @@ RtlCompareUnicodeString (
VOID
STDCALL
RtlCopyString (
RtlCopyString(
IN OUT PSTRING DestinationString,
IN PSTRING SourceString
)
IN PSTRING SourceString)
{
ULONG copylen, i;
PCHAR Src, Dest;
@ -414,10 +405,9 @@ RtlCopyString (
VOID
STDCALL
RtlCopyUnicodeString (
RtlCopyUnicodeString(
IN OUT PUNICODE_STRING DestinationString,
IN PUNICODE_STRING SourceString
)
IN PUNICODE_STRING SourceString)
{
ULONG copylen, i;
PWCHAR Src, Dest;
@ -447,10 +437,9 @@ RtlCopyUnicodeString (
BOOLEAN
STDCALL
RtlCreateUnicodeString (
RtlCreateUnicodeString(
IN OUT PUNICODE_STRING Destination,
IN PWSTR Source
)
IN PWSTR Source)
{
ULONG Length;
@ -473,8 +462,10 @@ RtlCreateUnicodeString (
}
BOOLEAN STDCALL
RtlCreateUnicodeStringFromAsciiz (OUT PUNICODE_STRING Destination,
BOOLEAN
STDCALL
RtlCreateUnicodeStringFromAsciiz(
OUT PUNICODE_STRING Destination,
IN PCSZ Source)
{
ANSI_STRING AnsiString;
@ -493,11 +484,10 @@ RtlCreateUnicodeStringFromAsciiz (OUT PUNICODE_STRING Destination,
NTSTATUS
STDCALL
RtlDowncaseUnicodeString (
RtlDowncaseUnicodeString(
IN OUT PUNICODE_STRING DestinationString,
IN PUNICODE_STRING SourceString,
IN BOOLEAN AllocateDestinationString
)
IN BOOLEAN AllocateDestinationString)
{
ULONG i;
PWCHAR Src, Dest;
@ -545,10 +535,9 @@ RtlDowncaseUnicodeString (
BOOLEAN
STDCALL
RtlEqualComputerName (
RtlEqualComputerName(
IN PUNICODE_STRING ComputerName1,
IN PUNICODE_STRING ComputerName2
)
IN PUNICODE_STRING ComputerName2)
{
return RtlEqualDomainName (ComputerName1,
ComputerName2);
@ -586,11 +575,10 @@ RtlEqualDomainName (
BOOLEAN
STDCALL
RtlEqualString (
RtlEqualString(
IN PSTRING String1,
IN PSTRING String2,
IN BOOLEAN CaseInsensitive
)
IN BOOLEAN CaseInsensitive)
{
ULONG i;
CHAR c1, c2;
@ -627,11 +615,10 @@ RtlEqualString (
BOOLEAN
STDCALL
RtlEqualUnicodeString (
RtlEqualUnicodeString(
IN PUNICODE_STRING String1,
IN PUNICODE_STRING String2,
IN BOOLEAN CaseInsensitive
)
IN BOOLEAN CaseInsensitive)
{
ULONG i;
WCHAR wc1, wc2;
@ -669,9 +656,8 @@ RtlEqualUnicodeString (
VOID
STDCALL
RtlEraseUnicodeString (
IN PUNICODE_STRING String
)
RtlEraseUnicodeString(
IN PUNICODE_STRING String)
{
if (String->Buffer == NULL)
return;
@ -689,9 +675,8 @@ RtlEraseUnicodeString (
VOID
STDCALL
RtlFreeAnsiString (
IN PANSI_STRING AnsiString
)
RtlFreeAnsiString(
IN PANSI_STRING AnsiString)
{
if (AnsiString->Buffer == NULL)
return;
@ -708,9 +693,8 @@ RtlFreeAnsiString (
VOID
STDCALL
RtlFreeOemString (
IN POEM_STRING OemString
)
RtlFreeOemString(
IN POEM_STRING OemString)
{
if (OemString->Buffer == NULL)
return;
@ -727,9 +711,8 @@ RtlFreeOemString (
VOID
STDCALL
RtlFreeUnicodeString (
IN PUNICODE_STRING UnicodeString
)
RtlFreeUnicodeString(
IN PUNICODE_STRING UnicodeString)
{
if (UnicodeString->Buffer == NULL)
return;
@ -746,10 +729,9 @@ RtlFreeUnicodeString (
VOID
STDCALL
RtlInitAnsiString (
RtlInitAnsiString(
IN OUT PANSI_STRING DestinationString,
IN PCSZ SourceString
)
IN PCSZ SourceString)
{
ULONG DestSize;
@ -770,10 +752,9 @@ RtlInitAnsiString (
VOID
STDCALL
RtlInitString (
RtlInitString(
IN OUT PSTRING DestinationString,
IN PCSZ SourceString
)
IN PCSZ SourceString)
{
ULONG DestSize;
@ -794,10 +775,9 @@ RtlInitString (
VOID
STDCALL
RtlInitUnicodeString (
RtlInitUnicodeString(
IN OUT PUNICODE_STRING DestinationString,
IN PCWSTR SourceString
)
IN PCWSTR SourceString)
{
ULONG DestSize;
@ -818,12 +798,11 @@ RtlInitUnicodeString (
NTSTATUS
STDCALL
RtlIntegerToChar (
RtlIntegerToChar(
IN ULONG Value,
IN ULONG Base,
IN ULONG Length,
IN OUT PCHAR String
)
IN OUT PCHAR String)
{
ULONG Radix;
CHAR temp[33];
@ -866,11 +845,10 @@ RtlIntegerToChar (
NTSTATUS
STDCALL
RtlIntegerToUnicodeString (
RtlIntegerToUnicodeString(
IN ULONG Value,
IN ULONG Base, /* optional */
IN OUT PUNICODE_STRING String
)
IN OUT PUNICODE_STRING String)
{
ANSI_STRING AnsiString;
CHAR Buffer[33];
@ -897,12 +875,11 @@ RtlIntegerToUnicodeString (
NTSTATUS
STDCALL
RtlLargeIntegerToChar (
RtlLargeIntegerToChar(
IN PLARGE_INTEGER Value,
IN ULONG Base,
IN ULONG Length,
IN OUT PCHAR String
)
IN OUT PCHAR String)
{
ULONG Radix;
CHAR temp[65];
@ -945,9 +922,8 @@ RtlLargeIntegerToChar (
ULONG
STDCALL
RtlOemStringToUnicodeSize (
IN POEM_STRING OemString
)
RtlOemStringToUnicodeSize(
IN POEM_STRING OemString)
{
ULONG Size;
@ -961,11 +937,10 @@ RtlOemStringToUnicodeSize (
NTSTATUS
STDCALL
RtlOemStringToUnicodeString (
RtlOemStringToUnicodeString(
IN OUT PUNICODE_STRING DestinationString,
IN POEM_STRING SourceString,
IN BOOLEAN AllocateDestinationString
)
IN BOOLEAN AllocateDestinationString)
{
NTSTATUS Status;
ULONG Length;
@ -1025,11 +1000,10 @@ RtlOemStringToUnicodeString (
BOOLEAN
STDCALL
RtlPrefixString (
RtlPrefixString(
PANSI_STRING String1,
PANSI_STRING String2,
BOOLEAN CaseInsensitive
)
BOOLEAN CaseInsensitive)
{
PCHAR pc1;
PCHAR pc2;
@ -1068,11 +1042,10 @@ RtlPrefixString (
BOOLEAN
STDCALL
RtlPrefixUnicodeString (
RtlPrefixUnicodeString(
PUNICODE_STRING String1,
PUNICODE_STRING String2,
BOOLEAN CaseInsensitive
)
BOOLEAN CaseInsensitive)
{
PWCHAR pc1;
PWCHAR pc2;
@ -1112,9 +1085,8 @@ RtlPrefixUnicodeString (
ULONG
STDCALL
RtlUnicodeStringToAnsiSize (
IN PUNICODE_STRING UnicodeString
)
RtlUnicodeStringToAnsiSize(
IN PUNICODE_STRING UnicodeString)
{
ULONG Size;
@ -1128,11 +1100,10 @@ RtlUnicodeStringToAnsiSize (
NTSTATUS
STDCALL
RtlUnicodeStringToAnsiString (
RtlUnicodeStringToAnsiString(
IN OUT PANSI_STRING DestinationString,
IN PUNICODE_STRING SourceString,
IN BOOLEAN AllocateDestinationString
)
IN BOOLEAN AllocateDestinationString)
{
NTSTATUS Status;
ULONG Length;
@ -1186,11 +1157,10 @@ RtlUnicodeStringToAnsiString (
NTSTATUS
STDCALL
RtlUnicodeStringToInteger (
RtlUnicodeStringToInteger(
IN PUNICODE_STRING String,
IN ULONG Base,
OUT PULONG Value
)
OUT PULONG Value)
{
PWCHAR Str;
ULONG lenmin = 0;
@ -1276,9 +1246,8 @@ RtlUnicodeStringToInteger (
ULONG
STDCALL
RtlUnicodeStringToOemSize (
IN PUNICODE_STRING UnicodeString
)
RtlUnicodeStringToOemSize(
IN PUNICODE_STRING UnicodeString)
{
ULONG Size;
@ -1292,11 +1261,10 @@ RtlUnicodeStringToOemSize (
NTSTATUS
STDCALL
RtlUnicodeStringToCountedOemString (
RtlUnicodeStringToCountedOemString(
IN OUT POEM_STRING DestinationString,
IN PUNICODE_STRING SourceString,
IN BOOLEAN AllocateDestinationString
)
IN BOOLEAN AllocateDestinationString)
{
NTSTATUS Status;
ULONG Length;
@ -1359,11 +1327,10 @@ RtlUnicodeStringToCountedOemString (
NTSTATUS
STDCALL
RtlUnicodeStringToOemString (
RtlUnicodeStringToOemString(
IN OUT POEM_STRING DestinationString,
IN PUNICODE_STRING SourceString,
IN BOOLEAN AllocateDestinationString
)
IN BOOLEAN AllocateDestinationString)
{
NTSTATUS Status;
ULONG Length;
@ -1426,9 +1393,7 @@ RtlUnicodeStringToOemString (
WCHAR
STDCALL
RtlUpcaseUnicodeChar (
IN WCHAR Source
)
RtlUpcaseUnicodeChar(IN WCHAR Source)
{
if (Source < L'a')
return Source;
@ -1444,11 +1409,10 @@ RtlUpcaseUnicodeChar (
NTSTATUS
STDCALL
RtlUpcaseUnicodeString (
RtlUpcaseUnicodeString(
IN OUT PUNICODE_STRING DestinationString,
IN PUNICODE_STRING SourceString,
IN BOOLEAN AllocateDestinationString
)
IN BOOLEAN AllocateDestinationString)
{
ULONG i;
PWCHAR Src, Dest;
@ -1485,11 +1449,10 @@ RtlUpcaseUnicodeString (
NTSTATUS
STDCALL
RtlUpcaseUnicodeStringToAnsiString (
RtlUpcaseUnicodeStringToAnsiString(
IN OUT PANSI_STRING DestinationString,
IN PUNICODE_STRING SourceString,
IN BOOLEAN AllocateDestinationString
)
IN BOOLEAN AllocateDestinationString)
{
NTSTATUS Status;
ULONG Length;
@ -1552,11 +1515,10 @@ RtlUpcaseUnicodeStringToAnsiString (
NTSTATUS
STDCALL
RtlUpcaseUnicodeStringToCountedOemString (
RtlUpcaseUnicodeStringToCountedOemString(
IN OUT POEM_STRING DestinationString,
IN PUNICODE_STRING SourceString,
IN BOOLEAN AllocateDestinationString
)
IN BOOLEAN AllocateDestinationString)
{
NTSTATUS Status;
ULONG Length;
@ -1724,10 +1686,9 @@ RtlUpperChar (
VOID
STDCALL
RtlUpperString (
RtlUpperString(
IN OUT PSTRING DestinationString,
IN PSTRING SourceString
)
IN PSTRING SourceString)
{
ULONG Length;
ULONG i;
@ -1752,41 +1713,33 @@ RtlUpperString (
ULONG
STDCALL
RtlxAnsiStringToUnicodeSize (
IN PANSI_STRING AnsiString
)
RtlxAnsiStringToUnicodeSize(IN PANSI_STRING AnsiString)
{
return RtlAnsiStringToUnicodeSize (AnsiString);
return RtlAnsiStringToUnicodeSize(AnsiString);
}
ULONG
STDCALL
RtlxOemStringToUnicodeSize (
IN POEM_STRING OemString
)
RtlxOemStringToUnicodeSize(IN POEM_STRING OemString)
{
return RtlAnsiStringToUnicodeSize ((PANSI_STRING)OemString);
return RtlAnsiStringToUnicodeSize((PANSI_STRING)OemString);
}
ULONG
STDCALL
RtlxUnicodeStringToAnsiSize (
IN PUNICODE_STRING UnicodeString
)
RtlxUnicodeStringToAnsiSize(IN PUNICODE_STRING UnicodeString)
{
return RtlUnicodeStringToAnsiSize (UnicodeString);
return RtlUnicodeStringToAnsiSize(UnicodeString);
}
ULONG
STDCALL
RtlxUnicodeStringToOemSize (
IN PUNICODE_STRING UnicodeString
)
RtlxUnicodeStringToOemSize(IN PUNICODE_STRING UnicodeString)
{
return RtlUnicodeStringToAnsiSize (UnicodeString);
return RtlUnicodeStringToAnsiSize(UnicodeString);
}
/* EOF */