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,6 +1462,7 @@ LdrAccessResource(IN PVOID BaseAddress,
return STATUS_SUCCESS;
}
#endif /*MOVED_TO_FILE_RES_C*/
NTSTATUS STDCALL
LdrDisableThreadCalloutsForDll(IN PVOID BaseAddress)
@ -1476,38 +1472,29 @@ LdrDisableThreadCalloutsForDll (IN PVOID BaseAddress)
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,8 +1590,10 @@ found:;
return Status;
}
#endif /*MOVED_TO_FILE_RES_C*/
NTSTATUS STDCALL
NTSTATUS
STDCALL
LdrGetDllHandle(IN ULONG Unknown1,
IN ULONG Unknown2,
IN PUNICODE_STRING DllName,
@ -1619,44 +1608,34 @@ 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))
{
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);
*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
@ -22,8 +22,7 @@
WCHAR
STDCALL
RtlAnsiCharToUnicodeChar(
IN CHAR AnsiChar
)
IN CHAR AnsiChar)
{
ULONG Size;
WCHAR UnicodeChar;
@ -46,8 +45,7 @@ RtlAnsiCharToUnicodeChar (
ULONG
STDCALL
RtlAnsiStringToUnicodeSize(
IN PANSI_STRING AnsiString
)
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;
@ -127,8 +124,7 @@ NTSTATUS
STDCALL
RtlAppendAsciizToString(
IN OUT PSTRING Destination,
IN PCSZ Source
)
IN PCSZ Source)
{
ULONG Length;
PCHAR Ptr;
@ -157,8 +153,7 @@ NTSTATUS
STDCALL
RtlAppendStringToString(
IN OUT PSTRING Destination,
IN PSTRING Source
)
IN PSTRING Source)
{
PCHAR Ptr;
@ -185,8 +180,7 @@ NTSTATUS
STDCALL
RtlAppendUnicodeStringToString(
IN OUT PUNICODE_STRING Destination,
IN PUNICODE_STRING Source
)
IN PUNICODE_STRING Source)
{
PWCHAR Src;
PWCHAR Dest;
@ -288,8 +282,7 @@ STDCALL
RtlCompareString(
IN PSTRING String1,
IN PSTRING String2,
IN BOOLEAN CaseInsensitive
)
IN BOOLEAN CaseInsensitive)
{
ULONG len1, len2;
PCHAR s1, s2;
@ -336,8 +329,7 @@ STDCALL
RtlCompareUnicodeString(
IN PUNICODE_STRING String1,
IN PUNICODE_STRING String2,
IN BOOLEAN CaseInsensitive
)
IN BOOLEAN CaseInsensitive)
{
ULONG len1, len2;
PWCHAR s1, s2;
@ -383,8 +375,7 @@ VOID
STDCALL
RtlCopyString(
IN OUT PSTRING DestinationString,
IN PSTRING SourceString
)
IN PSTRING SourceString)
{
ULONG copylen, i;
PCHAR Src, Dest;
@ -416,8 +407,7 @@ VOID
STDCALL
RtlCopyUnicodeString(
IN OUT PUNICODE_STRING DestinationString,
IN PUNICODE_STRING SourceString
)
IN PUNICODE_STRING SourceString)
{
ULONG copylen, i;
PWCHAR Src, Dest;
@ -449,8 +439,7 @@ BOOLEAN
STDCALL
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;
@ -496,8 +487,7 @@ STDCALL
RtlDowncaseUnicodeString(
IN OUT PUNICODE_STRING DestinationString,
IN PUNICODE_STRING SourceString,
IN BOOLEAN AllocateDestinationString
)
IN BOOLEAN AllocateDestinationString)
{
ULONG i;
PWCHAR Src, Dest;
@ -547,8 +537,7 @@ BOOLEAN
STDCALL
RtlEqualComputerName(
IN PUNICODE_STRING ComputerName1,
IN PUNICODE_STRING ComputerName2
)
IN PUNICODE_STRING ComputerName2)
{
return RtlEqualDomainName (ComputerName1,
ComputerName2);
@ -589,8 +578,7 @@ STDCALL
RtlEqualString(
IN PSTRING String1,
IN PSTRING String2,
IN BOOLEAN CaseInsensitive
)
IN BOOLEAN CaseInsensitive)
{
ULONG i;
CHAR c1, c2;
@ -630,8 +618,7 @@ STDCALL
RtlEqualUnicodeString(
IN PUNICODE_STRING String1,
IN PUNICODE_STRING String2,
IN BOOLEAN CaseInsensitive
)
IN BOOLEAN CaseInsensitive)
{
ULONG i;
WCHAR wc1, wc2;
@ -670,8 +657,7 @@ RtlEqualUnicodeString (
VOID
STDCALL
RtlEraseUnicodeString(
IN PUNICODE_STRING String
)
IN PUNICODE_STRING String)
{
if (String->Buffer == NULL)
return;
@ -690,8 +676,7 @@ RtlEraseUnicodeString (
VOID
STDCALL
RtlFreeAnsiString(
IN PANSI_STRING AnsiString
)
IN PANSI_STRING AnsiString)
{
if (AnsiString->Buffer == NULL)
return;
@ -709,8 +694,7 @@ RtlFreeAnsiString (
VOID
STDCALL
RtlFreeOemString(
IN POEM_STRING OemString
)
IN POEM_STRING OemString)
{
if (OemString->Buffer == NULL)
return;
@ -728,8 +712,7 @@ RtlFreeOemString (
VOID
STDCALL
RtlFreeUnicodeString(
IN PUNICODE_STRING UnicodeString
)
IN PUNICODE_STRING UnicodeString)
{
if (UnicodeString->Buffer == NULL)
return;
@ -748,8 +731,7 @@ VOID
STDCALL
RtlInitAnsiString(
IN OUT PANSI_STRING DestinationString,
IN PCSZ SourceString
)
IN PCSZ SourceString)
{
ULONG DestSize;
@ -772,8 +754,7 @@ VOID
STDCALL
RtlInitString(
IN OUT PSTRING DestinationString,
IN PCSZ SourceString
)
IN PCSZ SourceString)
{
ULONG DestSize;
@ -796,8 +777,7 @@ VOID
STDCALL
RtlInitUnicodeString(
IN OUT PUNICODE_STRING DestinationString,
IN PCWSTR SourceString
)
IN PCWSTR SourceString)
{
ULONG DestSize;
@ -822,8 +802,7 @@ RtlIntegerToChar (
IN ULONG Value,
IN ULONG Base,
IN ULONG Length,
IN OUT PCHAR String
)
IN OUT PCHAR String)
{
ULONG Radix;
CHAR temp[33];
@ -869,8 +848,7 @@ STDCALL
RtlIntegerToUnicodeString(
IN ULONG Value,
IN ULONG Base, /* optional */
IN OUT PUNICODE_STRING String
)
IN OUT PUNICODE_STRING String)
{
ANSI_STRING AnsiString;
CHAR Buffer[33];
@ -901,8 +879,7 @@ RtlLargeIntegerToChar (
IN PLARGE_INTEGER Value,
IN ULONG Base,
IN ULONG Length,
IN OUT PCHAR String
)
IN OUT PCHAR String)
{
ULONG Radix;
CHAR temp[65];
@ -946,8 +923,7 @@ RtlLargeIntegerToChar (
ULONG
STDCALL
RtlOemStringToUnicodeSize(
IN POEM_STRING OemString
)
IN POEM_STRING OemString)
{
ULONG Size;
@ -964,8 +940,7 @@ STDCALL
RtlOemStringToUnicodeString(
IN OUT PUNICODE_STRING DestinationString,
IN POEM_STRING SourceString,
IN BOOLEAN AllocateDestinationString
)
IN BOOLEAN AllocateDestinationString)
{
NTSTATUS Status;
ULONG Length;
@ -1028,8 +1003,7 @@ STDCALL
RtlPrefixString(
PANSI_STRING String1,
PANSI_STRING String2,
BOOLEAN CaseInsensitive
)
BOOLEAN CaseInsensitive)
{
PCHAR pc1;
PCHAR pc2;
@ -1071,8 +1045,7 @@ STDCALL
RtlPrefixUnicodeString(
PUNICODE_STRING String1,
PUNICODE_STRING String2,
BOOLEAN CaseInsensitive
)
BOOLEAN CaseInsensitive)
{
PWCHAR pc1;
PWCHAR pc2;
@ -1113,8 +1086,7 @@ RtlPrefixUnicodeString (
ULONG
STDCALL
RtlUnicodeStringToAnsiSize(
IN PUNICODE_STRING UnicodeString
)
IN PUNICODE_STRING UnicodeString)
{
ULONG Size;
@ -1131,8 +1103,7 @@ STDCALL
RtlUnicodeStringToAnsiString(
IN OUT PANSI_STRING DestinationString,
IN PUNICODE_STRING SourceString,
IN BOOLEAN AllocateDestinationString
)
IN BOOLEAN AllocateDestinationString)
{
NTSTATUS Status;
ULONG Length;
@ -1189,8 +1160,7 @@ STDCALL
RtlUnicodeStringToInteger(
IN PUNICODE_STRING String,
IN ULONG Base,
OUT PULONG Value
)
OUT PULONG Value)
{
PWCHAR Str;
ULONG lenmin = 0;
@ -1277,8 +1247,7 @@ RtlUnicodeStringToInteger (
ULONG
STDCALL
RtlUnicodeStringToOemSize(
IN PUNICODE_STRING UnicodeString
)
IN PUNICODE_STRING UnicodeString)
{
ULONG Size;
@ -1295,8 +1264,7 @@ STDCALL
RtlUnicodeStringToCountedOemString(
IN OUT POEM_STRING DestinationString,
IN PUNICODE_STRING SourceString,
IN BOOLEAN AllocateDestinationString
)
IN BOOLEAN AllocateDestinationString)
{
NTSTATUS Status;
ULONG Length;
@ -1362,8 +1330,7 @@ STDCALL
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;
@ -1447,8 +1412,7 @@ STDCALL
RtlUpcaseUnicodeString(
IN OUT PUNICODE_STRING DestinationString,
IN PUNICODE_STRING SourceString,
IN BOOLEAN AllocateDestinationString
)
IN BOOLEAN AllocateDestinationString)
{
ULONG i;
PWCHAR Src, Dest;
@ -1488,8 +1452,7 @@ STDCALL
RtlUpcaseUnicodeStringToAnsiString(
IN OUT PANSI_STRING DestinationString,
IN PUNICODE_STRING SourceString,
IN BOOLEAN AllocateDestinationString
)
IN BOOLEAN AllocateDestinationString)
{
NTSTATUS Status;
ULONG Length;
@ -1555,8 +1518,7 @@ STDCALL
RtlUpcaseUnicodeStringToCountedOemString(
IN OUT POEM_STRING DestinationString,
IN PUNICODE_STRING SourceString,
IN BOOLEAN AllocateDestinationString
)
IN BOOLEAN AllocateDestinationString)
{
NTSTATUS Status;
ULONG Length;
@ -1726,8 +1688,7 @@ VOID
STDCALL
RtlUpperString(
IN OUT PSTRING DestinationString,
IN PSTRING SourceString
)
IN PSTRING SourceString)
{
ULONG Length;
ULONG i;
@ -1752,9 +1713,7 @@ RtlUpperString (
ULONG
STDCALL
RtlxAnsiStringToUnicodeSize (
IN PANSI_STRING AnsiString
)
RtlxAnsiStringToUnicodeSize(IN PANSI_STRING AnsiString)
{
return RtlAnsiStringToUnicodeSize(AnsiString);
}
@ -1762,9 +1721,7 @@ RtlxAnsiStringToUnicodeSize (
ULONG
STDCALL
RtlxOemStringToUnicodeSize (
IN POEM_STRING OemString
)
RtlxOemStringToUnicodeSize(IN POEM_STRING OemString)
{
return RtlAnsiStringToUnicodeSize((PANSI_STRING)OemString);
}
@ -1772,9 +1729,7 @@ RtlxOemStringToUnicodeSize (
ULONG
STDCALL
RtlxUnicodeStringToAnsiSize (
IN PUNICODE_STRING UnicodeString
)
RtlxUnicodeStringToAnsiSize(IN PUNICODE_STRING UnicodeString)
{
return RtlUnicodeStringToAnsiSize(UnicodeString);
}
@ -1782,9 +1737,7 @@ RtlxUnicodeStringToAnsiSize (
ULONG
STDCALL
RtlxUnicodeStringToOemSize (
IN PUNICODE_STRING UnicodeString
)
RtlxUnicodeStringToOemSize(IN PUNICODE_STRING UnicodeString)
{
return RtlUnicodeStringToAnsiSize(UnicodeString);
}