2013-03-16 20:48:10 +00:00
|
|
|
/*
|
2011-07-22 03:21:17 +00:00
|
|
|
* COPYRIGHT: See COPYING in the top level directory
|
|
|
|
* PROJECT: ReactOS system libraries
|
|
|
|
* FILE: lib/kernel32/misc/time.c
|
|
|
|
* PURPOSE: Time conversion functions
|
|
|
|
* PROGRAMMER: Ariadne
|
|
|
|
* DOSDATE and DOSTIME structures from Onno Hovers
|
|
|
|
* UPDATE HISTORY:
|
|
|
|
* Created 19/01/99
|
|
|
|
*/
|
|
|
|
|
2011-07-26 14:05:30 +00:00
|
|
|
/* INCLUDES *******************************************************************/
|
2011-07-22 03:21:17 +00:00
|
|
|
|
|
|
|
#include <k32.h>
|
|
|
|
|
|
|
|
#define NDEBUG
|
|
|
|
#include <debug.h>
|
|
|
|
|
2011-07-26 14:05:30 +00:00
|
|
|
/* FUNCTIONS ******************************************************************/
|
2011-07-22 03:21:17 +00:00
|
|
|
|
2011-07-26 14:05:30 +00:00
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
BOOL
|
|
|
|
WINAPI
|
|
|
|
IsTimeZoneRedirectionEnabled(VOID)
|
2011-07-22 03:21:17 +00:00
|
|
|
{
|
2011-07-26 14:05:30 +00:00
|
|
|
/* Return if a TS Timezone ID is active */
|
|
|
|
return (BaseStaticServerData->TermsrvClientTimeZoneId != TIME_ZONE_ID_INVALID);
|
|
|
|
}
|
2011-07-22 03:21:17 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
BOOL
|
|
|
|
WINAPI
|
2011-07-26 14:05:30 +00:00
|
|
|
FileTimeToDosDateTime(IN CONST FILETIME *lpFileTime,
|
|
|
|
OUT LPWORD lpFatDate,
|
|
|
|
OUT LPWORD lpFatTime)
|
2011-07-22 03:21:17 +00:00
|
|
|
{
|
2011-07-26 14:05:30 +00:00
|
|
|
LARGE_INTEGER FileTime;
|
|
|
|
TIME_FIELDS TimeFields;
|
2011-07-22 03:21:17 +00:00
|
|
|
|
2011-07-26 14:05:30 +00:00
|
|
|
FileTime.HighPart = lpFileTime->dwHighDateTime;
|
|
|
|
FileTime.LowPart = lpFileTime->dwLowDateTime;
|
2011-07-22 03:21:17 +00:00
|
|
|
|
2011-07-26 14:05:30 +00:00
|
|
|
if (FileTime.QuadPart < 0)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
2011-07-22 03:21:17 +00:00
|
|
|
return FALSE;
|
2011-07-26 14:05:30 +00:00
|
|
|
}
|
2011-07-22 03:21:17 +00:00
|
|
|
|
2011-07-26 14:05:30 +00:00
|
|
|
RtlTimeToTimeFields(&FileTime, &TimeFields);
|
|
|
|
if ((TimeFields.Year < 1980) || (TimeFields.Year > 2107))
|
|
|
|
{
|
|
|
|
BaseSetLastNTError(STATUS_INVALID_PARAMETER);
|
2011-07-22 03:21:17 +00:00
|
|
|
return FALSE;
|
2011-07-26 14:05:30 +00:00
|
|
|
}
|
2011-07-22 03:21:17 +00:00
|
|
|
|
2011-07-26 14:05:30 +00:00
|
|
|
*lpFatDate = (TimeFields.Day) |
|
|
|
|
(TimeFields.Month << 5) |
|
|
|
|
((TimeFields.Year - 1980) << 9);
|
|
|
|
*lpFatTime = (TimeFields.Second >> 1) |
|
|
|
|
(TimeFields.Minute << 5) |
|
|
|
|
(TimeFields.Hour << 16);
|
2011-07-22 03:21:17 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
BOOL
|
|
|
|
WINAPI
|
2011-07-26 14:05:30 +00:00
|
|
|
DosDateTimeToFileTime(IN WORD wFatDate,
|
|
|
|
IN WORD wFatTime,
|
|
|
|
OUT LPFILETIME lpFileTime)
|
2011-07-22 03:21:17 +00:00
|
|
|
{
|
2011-07-26 14:05:30 +00:00
|
|
|
TIME_FIELDS TimeFields;
|
|
|
|
LARGE_INTEGER SystemTime;
|
2011-07-22 03:21:17 +00:00
|
|
|
|
2011-07-26 14:05:30 +00:00
|
|
|
TimeFields.Year = (wFatDate >> 9) + 1980;
|
|
|
|
TimeFields.Month = (wFatDate >> 5) & 0xF;
|
|
|
|
TimeFields.Day = (wFatDate & 0x1F);
|
|
|
|
TimeFields.Hour = (wFatTime >> 11);
|
|
|
|
TimeFields.Minute = (wFatTime >> 5) & 0x3F;
|
|
|
|
TimeFields.Second = (wFatTime & 0x1F) << 1;
|
|
|
|
TimeFields.Milliseconds = 0;
|
2011-07-22 03:21:17 +00:00
|
|
|
|
2011-07-26 14:05:30 +00:00
|
|
|
if (RtlTimeFieldsToTime(&TimeFields, &SystemTime))
|
2011-07-22 03:21:17 +00:00
|
|
|
{
|
2011-07-26 14:05:30 +00:00
|
|
|
lpFileTime->dwLowDateTime = SystemTime.LowPart;
|
|
|
|
lpFileTime->dwHighDateTime = SystemTime.HighPart;
|
|
|
|
return TRUE;
|
2011-07-22 03:21:17 +00:00
|
|
|
}
|
|
|
|
|
2011-07-26 14:05:30 +00:00
|
|
|
BaseSetLastNTError(STATUS_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
2011-07-22 03:21:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
LONG
|
|
|
|
WINAPI
|
2011-07-26 14:05:30 +00:00
|
|
|
CompareFileTime(IN CONST FILETIME *lpFileTime1,
|
|
|
|
IN CONST FILETIME *lpFileTime2)
|
2011-07-22 03:21:17 +00:00
|
|
|
{
|
2011-07-26 14:05:30 +00:00
|
|
|
LARGE_INTEGER Time1, Time2, Diff;
|
2011-07-22 03:21:17 +00:00
|
|
|
|
2011-07-26 14:05:30 +00:00
|
|
|
Time1.LowPart = lpFileTime1->dwLowDateTime;
|
|
|
|
Time2.LowPart = lpFileTime2->dwLowDateTime;
|
|
|
|
Time1.HighPart = lpFileTime1->dwHighDateTime;
|
|
|
|
Time2.HighPart = lpFileTime2->dwHighDateTime;
|
2011-07-22 03:21:17 +00:00
|
|
|
|
2011-07-26 14:05:30 +00:00
|
|
|
Diff.QuadPart = Time1.QuadPart - Time2.QuadPart;
|
2011-07-22 03:21:17 +00:00
|
|
|
|
2011-07-26 14:05:30 +00:00
|
|
|
if (Diff.HighPart < 0) return -1;
|
|
|
|
if (Diff.QuadPart == 0) return 0;
|
|
|
|
return 1;
|
|
|
|
}
|
2011-07-22 03:21:17 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
VOID
|
|
|
|
WINAPI
|
2011-07-26 14:05:30 +00:00
|
|
|
GetSystemTimeAsFileTime(OUT PFILETIME lpFileTime)
|
2011-07-22 03:21:17 +00:00
|
|
|
{
|
2011-07-26 14:05:30 +00:00
|
|
|
LARGE_INTEGER SystemTime;
|
|
|
|
|
2011-07-22 03:21:17 +00:00
|
|
|
do
|
|
|
|
{
|
2011-07-26 14:05:30 +00:00
|
|
|
SystemTime.HighPart = SharedUserData->SystemTime.High1Time;
|
|
|
|
SystemTime.LowPart = SharedUserData->SystemTime.LowPart;
|
2011-07-22 03:21:17 +00:00
|
|
|
}
|
2011-07-26 14:05:30 +00:00
|
|
|
while (SystemTime.HighPart != SharedUserData->SystemTime.High2Time);
|
2011-07-22 03:21:17 +00:00
|
|
|
|
2011-07-26 14:05:30 +00:00
|
|
|
lpFileTime->dwLowDateTime = SystemTime.LowPart;
|
|
|
|
lpFileTime->dwHighDateTime = SystemTime.HighPart;
|
|
|
|
}
|
2011-07-22 03:21:17 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
BOOL
|
|
|
|
WINAPI
|
2011-07-26 14:05:30 +00:00
|
|
|
SystemTimeToFileTime(IN CONST SYSTEMTIME *lpSystemTime,
|
|
|
|
OUT LPFILETIME lpFileTime)
|
2011-07-22 03:21:17 +00:00
|
|
|
{
|
|
|
|
TIME_FIELDS TimeFields;
|
|
|
|
LARGE_INTEGER liTime;
|
|
|
|
|
|
|
|
TimeFields.Year = lpSystemTime->wYear;
|
|
|
|
TimeFields.Month = lpSystemTime->wMonth;
|
|
|
|
TimeFields.Day = lpSystemTime->wDay;
|
|
|
|
TimeFields.Hour = lpSystemTime->wHour;
|
|
|
|
TimeFields.Minute = lpSystemTime->wMinute;
|
|
|
|
TimeFields.Second = lpSystemTime->wSecond;
|
|
|
|
TimeFields.Milliseconds = lpSystemTime->wMilliseconds;
|
|
|
|
|
2011-07-26 14:05:30 +00:00
|
|
|
if (RtlTimeFieldsToTime(&TimeFields, &liTime))
|
2011-07-22 03:21:17 +00:00
|
|
|
{
|
|
|
|
lpFileTime->dwLowDateTime = liTime.u.LowPart;
|
|
|
|
lpFileTime->dwHighDateTime = liTime.u.HighPart;
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2011-07-26 14:05:30 +00:00
|
|
|
BaseSetLastNTError(STATUS_INVALID_PARAMETER);
|
2011-07-22 03:21:17 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
BOOL
|
|
|
|
WINAPI
|
2011-07-26 14:05:30 +00:00
|
|
|
FileTimeToSystemTime(IN CONST FILETIME *lpFileTime,
|
|
|
|
OUT LPSYSTEMTIME lpSystemTime)
|
2011-07-22 03:21:17 +00:00
|
|
|
{
|
|
|
|
TIME_FIELDS TimeFields;
|
|
|
|
LARGE_INTEGER liTime;
|
|
|
|
|
|
|
|
liTime.u.LowPart = lpFileTime->dwLowDateTime;
|
|
|
|
liTime.u.HighPart = lpFileTime->dwHighDateTime;
|
2011-07-26 14:05:30 +00:00
|
|
|
if (liTime.QuadPart < 0)
|
|
|
|
{
|
|
|
|
SetLastError(ERROR_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
2011-07-22 03:21:17 +00:00
|
|
|
|
|
|
|
RtlTimeToTimeFields(&liTime, &TimeFields);
|
|
|
|
|
|
|
|
lpSystemTime->wYear = TimeFields.Year;
|
|
|
|
lpSystemTime->wMonth = TimeFields.Month;
|
|
|
|
lpSystemTime->wDay = TimeFields.Day;
|
|
|
|
lpSystemTime->wHour = TimeFields.Hour;
|
|
|
|
lpSystemTime->wMinute = TimeFields.Minute;
|
|
|
|
lpSystemTime->wSecond = TimeFields.Second;
|
|
|
|
lpSystemTime->wMilliseconds = TimeFields.Milliseconds;
|
|
|
|
lpSystemTime->wDayOfWeek = TimeFields.Weekday;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
BOOL
|
|
|
|
WINAPI
|
2011-07-26 14:05:30 +00:00
|
|
|
FileTimeToLocalFileTime(IN CONST FILETIME *lpFileTime,
|
|
|
|
OUT LPFILETIME lpLocalFileTime)
|
2011-07-22 03:21:17 +00:00
|
|
|
{
|
2011-07-26 14:05:30 +00:00
|
|
|
LARGE_INTEGER TimeZoneBias, FileTime;
|
|
|
|
volatile KSYSTEM_TIME *TimePtr;
|
2011-07-22 03:21:17 +00:00
|
|
|
|
2011-07-26 14:05:30 +00:00
|
|
|
TimePtr = IsTimeZoneRedirectionEnabled() ?
|
|
|
|
&BaseStaticServerData->ktTermsrvClientBias :
|
|
|
|
&SharedUserData->TimeZoneBias;
|
2011-07-22 03:21:17 +00:00
|
|
|
do
|
|
|
|
{
|
2011-07-26 14:05:30 +00:00
|
|
|
TimeZoneBias.HighPart = TimePtr->High1Time;
|
|
|
|
TimeZoneBias.LowPart = TimePtr->LowPart;
|
2011-07-22 03:21:17 +00:00
|
|
|
}
|
2011-07-26 14:05:30 +00:00
|
|
|
while (TimeZoneBias.HighPart != TimePtr->High2Time);
|
|
|
|
|
|
|
|
FileTime.LowPart = lpFileTime->dwLowDateTime;
|
|
|
|
FileTime.HighPart = lpFileTime->dwHighDateTime;
|
2011-07-22 03:21:17 +00:00
|
|
|
|
2011-07-26 14:05:30 +00:00
|
|
|
FileTime.QuadPart -= TimeZoneBias.QuadPart;
|
|
|
|
|
|
|
|
lpLocalFileTime->dwLowDateTime = FileTime.LowPart;
|
|
|
|
lpLocalFileTime->dwHighDateTime = FileTime.HighPart;
|
2011-07-22 03:21:17 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
BOOL
|
|
|
|
WINAPI
|
2011-07-26 14:05:30 +00:00
|
|
|
LocalFileTimeToFileTime(IN CONST FILETIME *lpLocalFileTime,
|
|
|
|
OUT LPFILETIME lpFileTime)
|
2011-07-22 03:21:17 +00:00
|
|
|
{
|
2011-07-26 14:05:30 +00:00
|
|
|
LARGE_INTEGER TimeZoneBias, FileTime;
|
|
|
|
volatile KSYSTEM_TIME *TimePtr;
|
|
|
|
|
|
|
|
TimePtr = IsTimeZoneRedirectionEnabled() ?
|
|
|
|
&BaseStaticServerData->ktTermsrvClientBias :
|
|
|
|
&SharedUserData->TimeZoneBias;
|
2011-07-22 03:21:17 +00:00
|
|
|
|
|
|
|
do
|
|
|
|
{
|
2011-07-26 14:05:30 +00:00
|
|
|
TimeZoneBias.HighPart = TimePtr->High1Time;
|
|
|
|
TimeZoneBias.LowPart = TimePtr->LowPart;
|
2011-07-22 03:21:17 +00:00
|
|
|
}
|
2011-07-26 14:05:30 +00:00
|
|
|
while (TimeZoneBias.HighPart != TimePtr->High2Time);
|
2011-07-22 03:21:17 +00:00
|
|
|
|
2011-07-26 14:05:30 +00:00
|
|
|
FileTime.LowPart = lpLocalFileTime->dwLowDateTime;
|
|
|
|
FileTime.HighPart = lpLocalFileTime->dwHighDateTime;
|
|
|
|
|
|
|
|
FileTime.QuadPart += TimeZoneBias.QuadPart;
|
|
|
|
|
|
|
|
lpFileTime->dwLowDateTime = FileTime.LowPart;
|
|
|
|
lpFileTime->dwHighDateTime = FileTime.HighPart;
|
2011-07-22 03:21:17 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
VOID
|
|
|
|
WINAPI
|
2011-07-26 14:05:30 +00:00
|
|
|
GetLocalTime(OUT LPSYSTEMTIME lpSystemTime)
|
2011-07-22 03:21:17 +00:00
|
|
|
{
|
2011-07-26 14:05:30 +00:00
|
|
|
LARGE_INTEGER SystemTime, TimeZoneBias;
|
|
|
|
TIME_FIELDS TimeFields;
|
|
|
|
volatile KSYSTEM_TIME *TimePtr;
|
2011-07-22 03:21:17 +00:00
|
|
|
|
2011-07-26 14:05:30 +00:00
|
|
|
do
|
|
|
|
{
|
|
|
|
SystemTime.HighPart = SharedUserData->SystemTime.High1Time;
|
|
|
|
SystemTime.LowPart = SharedUserData->SystemTime.LowPart;
|
|
|
|
}
|
|
|
|
while (SystemTime.HighPart != SharedUserData->SystemTime.High2Time);
|
|
|
|
|
|
|
|
TimePtr = IsTimeZoneRedirectionEnabled() ?
|
|
|
|
&BaseStaticServerData->ktTermsrvClientBias :
|
|
|
|
&SharedUserData->TimeZoneBias;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
TimeZoneBias.HighPart = TimePtr->High1Time;
|
|
|
|
TimeZoneBias.LowPart = TimePtr->LowPart;
|
|
|
|
}
|
|
|
|
while (TimeZoneBias.HighPart != TimePtr->High2Time);
|
2011-07-22 03:21:17 +00:00
|
|
|
|
2011-07-26 14:05:30 +00:00
|
|
|
SystemTime.QuadPart -= TimeZoneBias.QuadPart;
|
|
|
|
RtlTimeToTimeFields(&SystemTime, &TimeFields);
|
|
|
|
|
|
|
|
lpSystemTime->wYear = TimeFields.Year;
|
|
|
|
lpSystemTime->wMonth = TimeFields.Month;
|
|
|
|
lpSystemTime->wDay = TimeFields.Day;
|
|
|
|
lpSystemTime->wHour = TimeFields.Hour;
|
|
|
|
lpSystemTime->wMinute = TimeFields.Minute;
|
|
|
|
lpSystemTime->wSecond = TimeFields.Second;
|
|
|
|
lpSystemTime->wMilliseconds = TimeFields.Milliseconds;
|
|
|
|
lpSystemTime->wDayOfWeek = TimeFields.Weekday;
|
|
|
|
}
|
2011-07-22 03:21:17 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
VOID
|
|
|
|
WINAPI
|
2011-07-26 14:05:30 +00:00
|
|
|
GetSystemTime(OUT LPSYSTEMTIME lpSystemTime)
|
2011-07-22 03:21:17 +00:00
|
|
|
{
|
2011-07-26 14:05:30 +00:00
|
|
|
LARGE_INTEGER SystemTime;
|
|
|
|
TIME_FIELDS TimeFields;
|
2011-07-22 03:21:17 +00:00
|
|
|
|
2011-07-26 14:05:30 +00:00
|
|
|
do
|
|
|
|
{
|
|
|
|
SystemTime.HighPart = SharedUserData->SystemTime.High1Time;
|
|
|
|
SystemTime.LowPart = SharedUserData->SystemTime.LowPart;
|
|
|
|
}
|
|
|
|
while (SystemTime.HighPart != SharedUserData->SystemTime.High2Time);
|
|
|
|
|
|
|
|
RtlTimeToTimeFields(&SystemTime, &TimeFields);
|
2011-07-22 03:21:17 +00:00
|
|
|
|
2011-07-26 14:05:30 +00:00
|
|
|
lpSystemTime->wYear = TimeFields.Year;
|
|
|
|
lpSystemTime->wMonth = TimeFields.Month;
|
|
|
|
lpSystemTime->wDay = TimeFields.Day;
|
|
|
|
lpSystemTime->wHour = TimeFields.Hour;
|
|
|
|
lpSystemTime->wMinute = TimeFields.Minute;
|
|
|
|
lpSystemTime->wSecond = TimeFields.Second;
|
|
|
|
lpSystemTime->wMilliseconds = TimeFields.Milliseconds;
|
|
|
|
lpSystemTime->wDayOfWeek = TimeFields.Weekday;
|
|
|
|
}
|
2011-07-22 03:21:17 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
BOOL
|
|
|
|
WINAPI
|
2011-07-26 14:05:30 +00:00
|
|
|
SetLocalTime(IN CONST SYSTEMTIME *lpSystemTime)
|
2011-07-22 03:21:17 +00:00
|
|
|
{
|
2011-07-26 14:05:30 +00:00
|
|
|
LARGE_INTEGER NewSystemTime, TimeZoneBias;
|
2011-07-22 03:21:17 +00:00
|
|
|
NTSTATUS Status;
|
2011-07-26 14:05:30 +00:00
|
|
|
ULONG Privilege = SE_SYSTEMTIME_PRIVILEGE;
|
|
|
|
TIME_FIELDS TimeFields;
|
|
|
|
PVOID State;
|
|
|
|
volatile KSYSTEM_TIME *TimePtr;
|
|
|
|
|
|
|
|
TimePtr = IsTimeZoneRedirectionEnabled() ?
|
|
|
|
&BaseStaticServerData->ktTermsrvClientBias :
|
|
|
|
&SharedUserData->TimeZoneBias;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
TimeZoneBias.HighPart = TimePtr->High1Time;
|
|
|
|
TimeZoneBias.LowPart = TimePtr->LowPart;
|
|
|
|
}
|
|
|
|
while (TimeZoneBias.HighPart != TimePtr->High2Time);
|
|
|
|
|
|
|
|
TimeFields.Year = lpSystemTime->wYear;
|
|
|
|
TimeFields.Month = lpSystemTime->wMonth;
|
|
|
|
TimeFields.Day = lpSystemTime->wDay;
|
|
|
|
TimeFields.Hour = lpSystemTime->wHour;
|
|
|
|
TimeFields.Minute = lpSystemTime->wMinute;
|
|
|
|
TimeFields.Second = lpSystemTime->wSecond;
|
|
|
|
TimeFields.Milliseconds = lpSystemTime->wMilliseconds;
|
|
|
|
|
|
|
|
if (!RtlTimeFieldsToTime(&TimeFields, &NewSystemTime))
|
|
|
|
{
|
|
|
|
BaseSetLastNTError(STATUS_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NewSystemTime.QuadPart += TimeZoneBias.QuadPart;
|
|
|
|
|
|
|
|
Status = RtlAcquirePrivilege(&Privilege, 1, 0, &State);
|
|
|
|
if (NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
Status = NtSetSystemTime(&NewSystemTime, NULL);
|
|
|
|
RtlReleasePrivilege(State);
|
|
|
|
}
|
2011-07-22 03:21:17 +00:00
|
|
|
|
|
|
|
if (!NT_SUCCESS(Status))
|
2011-07-26 14:05:30 +00:00
|
|
|
{
|
|
|
|
BaseSetLastNTError(Status);
|
2011-07-22 03:21:17 +00:00
|
|
|
return FALSE;
|
2011-07-26 14:05:30 +00:00
|
|
|
}
|
|
|
|
|
2011-07-22 03:21:17 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
BOOL
|
|
|
|
WINAPI
|
2011-07-26 14:05:30 +00:00
|
|
|
SetSystemTime(IN CONST SYSTEMTIME *lpSystemTime)
|
2011-07-22 03:21:17 +00:00
|
|
|
{
|
|
|
|
LARGE_INTEGER NewSystemTime;
|
|
|
|
NTSTATUS Status;
|
2011-07-26 14:05:30 +00:00
|
|
|
ULONG Privilege = SE_SYSTEMTIME_PRIVILEGE;
|
|
|
|
TIME_FIELDS TimeFields;
|
|
|
|
PVOID State;
|
|
|
|
|
|
|
|
TimeFields.Year = lpSystemTime->wYear;
|
|
|
|
TimeFields.Month = lpSystemTime->wMonth;
|
|
|
|
TimeFields.Day = lpSystemTime->wDay;
|
|
|
|
TimeFields.Hour = lpSystemTime->wHour;
|
|
|
|
TimeFields.Minute = lpSystemTime->wMinute;
|
|
|
|
TimeFields.Second = lpSystemTime->wSecond;
|
|
|
|
TimeFields.Milliseconds = lpSystemTime->wMilliseconds;
|
|
|
|
|
|
|
|
if (!RtlTimeFieldsToTime(&TimeFields, &NewSystemTime))
|
|
|
|
{
|
|
|
|
BaseSetLastNTError(STATUS_INVALID_PARAMETER);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
Status = RtlAcquirePrivilege(&Privilege, 1, 0, &State);
|
|
|
|
if (NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
Status = NtSetSystemTime(&NewSystemTime, NULL);
|
|
|
|
RtlReleasePrivilege(State);
|
|
|
|
}
|
2011-07-22 03:21:17 +00:00
|
|
|
|
|
|
|
if (!NT_SUCCESS(Status))
|
2011-07-26 14:05:30 +00:00
|
|
|
{
|
|
|
|
BaseSetLastNTError(Status);
|
2011-07-22 03:21:17 +00:00
|
|
|
return FALSE;
|
2011-07-26 14:05:30 +00:00
|
|
|
}
|
|
|
|
|
2011-07-22 03:21:17 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
DWORD
|
|
|
|
WINAPI
|
|
|
|
GetTickCount(VOID)
|
|
|
|
{
|
|
|
|
ULARGE_INTEGER TickCount;
|
|
|
|
|
|
|
|
while (TRUE)
|
|
|
|
{
|
|
|
|
TickCount.HighPart = (ULONG)SharedUserData->TickCount.High1Time;
|
|
|
|
TickCount.LowPart = SharedUserData->TickCount.LowPart;
|
|
|
|
|
|
|
|
if (TickCount.HighPart == (ULONG)SharedUserData->TickCount.High2Time)
|
|
|
|
break;
|
|
|
|
|
|
|
|
YieldProcessor();
|
|
|
|
}
|
|
|
|
|
2011-07-26 14:05:30 +00:00
|
|
|
return (ULONG)((UInt32x32To64(TickCount.LowPart,
|
|
|
|
SharedUserData->TickCountMultiplier) >> 24) +
|
|
|
|
UInt32x32To64((TickCount.HighPart << 8) & 0xFFFFFFFF,
|
|
|
|
SharedUserData->TickCountMultiplier));
|
2011-07-22 03:21:17 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
BOOL
|
|
|
|
WINAPI
|
2011-07-26 14:05:30 +00:00
|
|
|
GetSystemTimeAdjustment(OUT PDWORD lpTimeAdjustment,
|
|
|
|
OUT PDWORD lpTimeIncrement,
|
|
|
|
OUT PBOOL lpTimeAdjustmentDisabled)
|
2011-07-22 03:21:17 +00:00
|
|
|
{
|
2011-07-26 14:05:30 +00:00
|
|
|
SYSTEM_QUERY_TIME_ADJUST_INFORMATION TimeInfo;
|
2011-07-22 03:21:17 +00:00
|
|
|
NTSTATUS Status;
|
|
|
|
|
|
|
|
Status = NtQuerySystemInformation(SystemTimeAdjustmentInformation,
|
2011-07-26 14:05:30 +00:00
|
|
|
&TimeInfo,
|
|
|
|
sizeof(TimeInfo),
|
2011-07-22 03:21:17 +00:00
|
|
|
NULL);
|
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
2011-07-23 18:54:29 +00:00
|
|
|
BaseSetLastNTError(Status);
|
2011-07-22 03:21:17 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2011-07-26 14:05:30 +00:00
|
|
|
*lpTimeAdjustment = (DWORD)TimeInfo.TimeAdjustment;
|
|
|
|
*lpTimeIncrement = (DWORD)TimeInfo.TimeIncrement;
|
|
|
|
*lpTimeAdjustmentDisabled = (BOOL)TimeInfo.Enable;
|
2011-07-22 03:21:17 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
BOOL
|
|
|
|
WINAPI
|
2011-07-26 14:05:30 +00:00
|
|
|
SetSystemTimeAdjustment(IN DWORD dwTimeAdjustment,
|
|
|
|
IN BOOL bTimeAdjustmentDisabled)
|
2011-07-22 03:21:17 +00:00
|
|
|
{
|
|
|
|
NTSTATUS Status;
|
2011-07-26 14:05:30 +00:00
|
|
|
SYSTEM_SET_TIME_ADJUST_INFORMATION TimeInfo;
|
2011-07-22 03:21:17 +00:00
|
|
|
|
2011-07-26 14:05:30 +00:00
|
|
|
TimeInfo.TimeAdjustment = (ULONG)dwTimeAdjustment;
|
|
|
|
TimeInfo.Enable = (BOOLEAN)bTimeAdjustmentDisabled;
|
2011-07-22 03:21:17 +00:00
|
|
|
|
|
|
|
Status = NtSetSystemInformation(SystemTimeAdjustmentInformation,
|
2011-07-26 14:05:30 +00:00
|
|
|
&TimeInfo,
|
|
|
|
sizeof(TimeInfo));
|
2011-07-22 03:21:17 +00:00
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
2011-07-23 18:54:29 +00:00
|
|
|
BaseSetLastNTError(Status);
|
2011-07-22 03:21:17 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* @implemented
|
|
|
|
*/
|
|
|
|
BOOL
|
|
|
|
WINAPI
|
2011-07-26 14:05:30 +00:00
|
|
|
GetSystemTimes(OUT LPFILETIME lpIdleTime OPTIONAL,
|
|
|
|
OUT LPFILETIME lpKernelTime OPTIONAL,
|
|
|
|
OUT LPFILETIME lpUserTime OPTIONAL)
|
2011-07-22 03:21:17 +00:00
|
|
|
{
|
2011-07-26 14:05:30 +00:00
|
|
|
PSYSTEM_PROCESSOR_PERFORMANCE_INFORMATION ProcPerfInfo;
|
|
|
|
LARGE_INTEGER TotalUserTime, TotalKernTime, TotalIdleTime;
|
|
|
|
SIZE_T BufferSize, ReturnLength;
|
|
|
|
ULONG i;
|
2011-07-22 03:21:17 +00:00
|
|
|
NTSTATUS Status;
|
|
|
|
|
2011-07-26 14:05:30 +00:00
|
|
|
TotalUserTime.QuadPart = TotalKernTime.QuadPart = TotalIdleTime.QuadPart = 0;
|
|
|
|
|
|
|
|
BufferSize = sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION) *
|
|
|
|
BaseStaticServerData->SysInfo.NumberOfProcessors;
|
|
|
|
|
|
|
|
ProcPerfInfo = RtlAllocateHeap(RtlGetProcessHeap(), 0, BufferSize);
|
|
|
|
if (!ProcPerfInfo)
|
|
|
|
{
|
|
|
|
BaseSetLastNTError(STATUS_NO_MEMORY);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2012-04-25 10:17:29 +00:00
|
|
|
Status = NtQuerySystemInformation(SystemProcessorPerformanceInformation,
|
2011-07-26 14:05:30 +00:00
|
|
|
ProcPerfInfo,
|
|
|
|
BufferSize,
|
|
|
|
&ReturnLength);
|
|
|
|
if ((NT_SUCCESS(Status)) && (ReturnLength == BufferSize))
|
|
|
|
{
|
|
|
|
if (lpIdleTime)
|
|
|
|
{
|
|
|
|
for (i = 0; i < BaseStaticServerData->SysInfo.NumberOfProcessors; i++)
|
|
|
|
{
|
|
|
|
TotalIdleTime.QuadPart += ProcPerfInfo[i].IdleTime.QuadPart;
|
|
|
|
}
|
|
|
|
|
|
|
|
lpIdleTime->dwLowDateTime = TotalIdleTime.LowPart;
|
|
|
|
lpIdleTime->dwHighDateTime = TotalIdleTime.HighPart;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lpKernelTime)
|
|
|
|
{
|
|
|
|
for (i = 0; i < BaseStaticServerData->SysInfo.NumberOfProcessors; i++)
|
|
|
|
{
|
|
|
|
TotalKernTime.QuadPart += ProcPerfInfo[i].KernelTime.QuadPart;
|
|
|
|
}
|
|
|
|
|
|
|
|
lpKernelTime->dwLowDateTime = TotalKernTime.LowPart;
|
|
|
|
lpKernelTime->dwHighDateTime = TotalKernTime.HighPart;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lpUserTime)
|
|
|
|
{
|
|
|
|
for (i = 0; i < BaseStaticServerData->SysInfo.NumberOfProcessors; i++)
|
|
|
|
{
|
|
|
|
TotalUserTime.QuadPart += ProcPerfInfo[i].UserTime.QuadPart;
|
|
|
|
}
|
|
|
|
|
|
|
|
lpUserTime->dwLowDateTime = TotalUserTime.LowPart;
|
|
|
|
lpUserTime->dwHighDateTime = TotalUserTime.HighPart;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (NT_SUCCESS(Status))
|
|
|
|
{
|
|
|
|
Status = STATUS_INTERNAL_ERROR;
|
|
|
|
}
|
2011-07-22 03:21:17 +00:00
|
|
|
|
2011-07-26 14:05:30 +00:00
|
|
|
RtlFreeHeap(RtlGetProcessHeap(), 0, ProcPerfInfo);
|
2011-07-22 03:21:17 +00:00
|
|
|
if (!NT_SUCCESS(Status))
|
|
|
|
{
|
2011-07-23 18:54:29 +00:00
|
|
|
BaseSetLastNTError(Status);
|
2011-07-22 03:21:17 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2011-07-24 23:42:09 +00:00
|
|
|
/*
|
2011-07-26 14:05:30 +00:00
|
|
|
* @unimplemented
|
2011-07-24 23:42:09 +00:00
|
|
|
*/
|
|
|
|
BOOL
|
|
|
|
WINAPI
|
2011-07-26 14:05:30 +00:00
|
|
|
SetClientTimeZoneInformation(IN CONST TIME_ZONE_INFORMATION *lpTimeZoneInformation)
|
2011-07-24 23:42:09 +00:00
|
|
|
{
|
2011-07-26 14:05:30 +00:00
|
|
|
STUB;
|
|
|
|
return 0;
|
2011-07-24 23:42:09 +00:00
|
|
|
}
|
2011-07-22 03:21:17 +00:00
|
|
|
|
|
|
|
/* EOF */
|