2 * Win32 kernel time functions
4 * Copyright 1995 Martin von Loewis and Cameron Heide
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
30 #ifdef HAVE_SYS_TIME_H
31 # include <sys/time.h>
33 #ifdef HAVE_SYS_TIMES_H
34 # include <sys/times.h>
36 #ifdef HAVE_SYS_LIMITS_H
37 #include <sys/limits.h>
38 #elif defined(HAVE_MACHINE_LIMITS_H)
39 #include <machine/limits.h>
43 #define WIN32_NO_STATUS
44 #define NONAMELESSUNION
48 #include "kernel_private.h"
49 #include "wine/unicode.h"
50 #include "wine/debug.h"
52 WINE_DEFAULT_DEBUG_CHANNEL(time
);
54 #define CALINFO_MAX_YEAR 2029
56 #define LL2FILETIME( ll, pft )\
57 (pft)->dwLowDateTime = (UINT)(ll); \
58 (pft)->dwHighDateTime = (UINT)((ll) >> 32);
59 #define FILETIME2LL( pft, ll) \
60 ll = (((LONGLONG)((pft)->dwHighDateTime))<<32) + (pft)-> dwLowDateTime ;
62 static const WCHAR mui_stdW
[] = { 'M','U','I','_','S','t','d',0 };
63 static const WCHAR mui_dltW
[] = { 'M','U','I','_','D','l','t',0 };
65 static const int MonthLengths
[2][12] =
67 { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
68 { 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
71 static inline BOOL
IsLeapYear(int Year
)
73 return Year
% 4 == 0 && (Year
% 100 != 0 || Year
% 400 == 0);
76 /***********************************************************************
77 * TIME_DayLightCompareDate
79 * Compares two dates without looking at the year.
82 * date [in] The local time to compare.
83 * compareDate [in] The daylight savings begin or end date.
87 * -1 if date < compareDate
88 * 0 if date == compareDate
89 * 1 if date > compareDate
90 * -2 if an error occurs
92 static int TIME_DayLightCompareDate( const SYSTEMTIME
*date
,
93 const SYSTEMTIME
*compareDate
)
95 int limit_day
, dayinsecs
;
97 if (date
->wMonth
< compareDate
->wMonth
)
98 return -1; /* We are in a month before the date limit. */
100 if (date
->wMonth
> compareDate
->wMonth
)
101 return 1; /* We are in a month after the date limit. */
103 /* if year is 0 then date is in day-of-week format, otherwise
104 * it's absolute date.
106 if (compareDate
->wYear
== 0)
109 /* compareDate->wDay is interpreted as number of the week in the month
110 * 5 means: the last week in the month */
111 int weekofmonth
= compareDate
->wDay
;
112 /* calculate the day of the first DayOfWeek in the month */
113 First
= ( 6 + compareDate
->wDayOfWeek
- date
->wDayOfWeek
+ date
->wDay
115 limit_day
= First
+ 7 * (weekofmonth
- 1);
116 /* check needed for the 5th weekday of the month */
117 if(limit_day
> MonthLengths
[date
->wMonth
==2 && IsLeapYear(date
->wYear
)]
123 limit_day
= compareDate
->wDay
;
126 /* convert to seconds */
127 limit_day
= ((limit_day
* 24 + compareDate
->wHour
) * 60 +
128 compareDate
->wMinute
) * 60;
129 dayinsecs
= ((date
->wDay
* 24 + date
->wHour
) * 60 +
130 date
->wMinute
) * 60 + date
->wSecond
;
132 return dayinsecs
< limit_day
? -1 :
133 dayinsecs
> limit_day
? 1 :
134 0; /* date is equal to the date limit. */
137 /***********************************************************************
138 * TIME_CompTimeZoneID
140 * Computes the local time bias for a given time and time zone.
143 * pTZinfo [in] The time zone data.
144 * lpFileTime [in] The system or local time.
145 * islocal [in] it is local time.
148 * TIME_ZONE_ID_INVALID An error occurred
149 * TIME_ZONE_ID_UNKNOWN There are no transition time known
150 * TIME_ZONE_ID_STANDARD Current time is standard time
151 * TIME_ZONE_ID_DAYLIGHT Current time is daylight savings time
153 static DWORD
TIME_CompTimeZoneID ( const TIME_ZONE_INFORMATION
*pTZinfo
,
154 FILETIME
*lpFileTime
, BOOL islocal
)
157 BOOL beforeStandardDate
, afterDaylightDate
;
158 DWORD retval
= TIME_ZONE_ID_INVALID
;
159 LONGLONG llTime
= 0; /* initialized to prevent gcc complaining */
163 if (pTZinfo
->DaylightDate
.wMonth
!= 0)
165 /* if year is 0 then date is in day-of-week format, otherwise
166 * it's absolute date.
168 if (pTZinfo
->StandardDate
.wMonth
== 0 ||
169 (pTZinfo
->StandardDate
.wYear
== 0 &&
170 (pTZinfo
->StandardDate
.wDay
<1 ||
171 pTZinfo
->StandardDate
.wDay
>5 ||
172 pTZinfo
->DaylightDate
.wDay
<1 ||
173 pTZinfo
->DaylightDate
.wDay
>5)))
175 SetLastError(ERROR_INVALID_PARAMETER
);
176 return TIME_ZONE_ID_INVALID
;
180 FILETIME2LL( lpFileTime
, llTime
);
181 llTime
-= pTZinfo
->Bias
* (LONGLONG
)600000000;
182 LL2FILETIME( llTime
, &ftTemp
)
183 lpFileTime
= &ftTemp
;
186 FileTimeToSystemTime(lpFileTime
, &SysTime
);
187 year
= SysTime
.wYear
;
190 llTime
-= pTZinfo
->DaylightBias
* (LONGLONG
)600000000;
191 LL2FILETIME( llTime
, &ftTemp
)
192 FileTimeToSystemTime(lpFileTime
, &SysTime
);
195 /* check for daylight savings */
196 if(year
== SysTime
.wYear
) {
197 ret
= TIME_DayLightCompareDate( &SysTime
, &pTZinfo
->StandardDate
);
199 return TIME_ZONE_ID_INVALID
;
201 beforeStandardDate
= ret
< 0;
203 beforeStandardDate
= SysTime
.wYear
< year
;
206 llTime
-= ( pTZinfo
->StandardBias
- pTZinfo
->DaylightBias
)
207 * (LONGLONG
)600000000;
208 LL2FILETIME( llTime
, &ftTemp
)
209 FileTimeToSystemTime(lpFileTime
, &SysTime
);
212 if(year
== SysTime
.wYear
) {
213 ret
= TIME_DayLightCompareDate( &SysTime
, &pTZinfo
->DaylightDate
);
215 return TIME_ZONE_ID_INVALID
;
217 afterDaylightDate
= ret
>= 0;
219 afterDaylightDate
= SysTime
.wYear
> year
;
221 retval
= TIME_ZONE_ID_STANDARD
;
222 if( pTZinfo
->DaylightDate
.wMonth
< pTZinfo
->StandardDate
.wMonth
) {
223 /* Northern hemisphere */
224 if( beforeStandardDate
&& afterDaylightDate
)
225 retval
= TIME_ZONE_ID_DAYLIGHT
;
226 } else /* Down south */
227 if( beforeStandardDate
|| afterDaylightDate
)
228 retval
= TIME_ZONE_ID_DAYLIGHT
;
230 /* No transition date */
231 retval
= TIME_ZONE_ID_UNKNOWN
;
236 /***********************************************************************
239 * Calculates whether daylight savings is on now.
242 * pTzi [in] Timezone info.
245 * TIME_ZONE_ID_INVALID An error occurred
246 * TIME_ZONE_ID_UNKNOWN There are no transition time known
247 * TIME_ZONE_ID_STANDARD Current time is standard time
248 * TIME_ZONE_ID_DAYLIGHT Current time is daylight savings time
250 static DWORD
TIME_ZoneID( const TIME_ZONE_INFORMATION
*pTzi
)
253 GetSystemTimeAsFileTime( &ftTime
);
254 return TIME_CompTimeZoneID( pTzi
, &ftTime
, FALSE
);
257 /***********************************************************************
258 * TIME_GetTimezoneBias
260 * Calculates the local time bias for a given time zone.
263 * pTZinfo [in] The time zone data.
264 * lpFileTime [in] The system or local time.
265 * islocal [in] It is local time.
266 * pBias [out] The calculated bias in minutes.
269 * TRUE when the time zone bias was calculated.
271 static BOOL
TIME_GetTimezoneBias( const TIME_ZONE_INFORMATION
*pTZinfo
,
272 FILETIME
*lpFileTime
, BOOL islocal
, LONG
*pBias
)
274 LONG bias
= pTZinfo
->Bias
;
275 DWORD tzid
= TIME_CompTimeZoneID( pTZinfo
, lpFileTime
, islocal
);
277 if( tzid
== TIME_ZONE_ID_INVALID
)
279 if (tzid
== TIME_ZONE_ID_DAYLIGHT
)
280 bias
+= pTZinfo
->DaylightBias
;
281 else if (tzid
== TIME_ZONE_ID_STANDARD
)
282 bias
+= pTZinfo
->StandardBias
;
287 /***********************************************************************
288 * TIME_GetSpecificTimeZoneKey
290 * Opens the registry key for the time zone with the given name.
293 * key_name [in] The time zone name.
294 * result [out] The open registry key handle.
297 * TRUE if successful.
299 static BOOL
TIME_GetSpecificTimeZoneKey( const WCHAR
*key_name
, HANDLE
*result
)
301 static const WCHAR Time_ZonesW
[] = { '\\','R','E','G','I','S','T','R','Y','\\',
302 'M','a','c','h','i','n','e','\\',
303 'S','o','f','t','w','a','r','e','\\',
304 'M','i','c','r','o','s','o','f','t','\\',
305 'W','i','n','d','o','w','s',' ','N','T','\\',
306 'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
307 'T','i','m','e',' ','Z','o','n','e','s',0 };
308 HANDLE time_zones_key
;
309 OBJECT_ATTRIBUTES attr
;
310 UNICODE_STRING nameW
;
313 attr
.Length
= sizeof(attr
);
314 attr
.RootDirectory
= 0;
315 attr
.ObjectName
= &nameW
;
317 attr
.SecurityDescriptor
= NULL
;
318 attr
.SecurityQualityOfService
= NULL
;
319 RtlInitUnicodeString( &nameW
, Time_ZonesW
);
320 status
= NtOpenKey( &time_zones_key
, KEY_READ
, &attr
);
323 WARN("Unable to open the time zones key\n");
324 SetLastError( RtlNtStatusToDosError(status
) );
328 attr
.RootDirectory
= time_zones_key
;
329 RtlInitUnicodeString( &nameW
, key_name
);
330 status
= NtOpenKey( result
, KEY_READ
, &attr
);
332 NtClose( time_zones_key
);
336 SetLastError( RtlNtStatusToDosError(status
) );
343 static BOOL
reg_query_value(HKEY hkey
, LPCWSTR name
, DWORD type
, void *data
, DWORD count
)
345 UNICODE_STRING nameW
;
347 KEY_VALUE_PARTIAL_INFORMATION
*info
= (KEY_VALUE_PARTIAL_INFORMATION
*)buf
;
350 if (count
> sizeof(buf
) - sizeof(KEY_VALUE_PARTIAL_INFORMATION
))
353 RtlInitUnicodeString(&nameW
, name
);
355 if ((status
= NtQueryValueKey(hkey
, &nameW
, KeyValuePartialInformation
,
356 buf
, sizeof(buf
), &count
)))
358 SetLastError( RtlNtStatusToDosError(status
) );
362 if (info
->Type
!= type
)
364 SetLastError( ERROR_DATATYPE_MISMATCH
);
368 memcpy(data
, info
->Data
, info
->DataLength
);
372 static BOOL
reg_load_mui_string(HKEY hkey
, LPCWSTR value
, LPWSTR buffer
, DWORD size
)
374 static const WCHAR advapi32W
[] = {'a','d','v','a','p','i','3','2','.','d','l','l',0};
375 DWORD (WINAPI
*pRegLoadMUIStringW
)(HKEY
, LPCWSTR
, LPWSTR
, DWORD
, DWORD
*, DWORD
, LPCWSTR
);
379 hDll
= LoadLibraryExW(advapi32W
, NULL
, LOAD_LIBRARY_SEARCH_SYSTEM32
);
381 pRegLoadMUIStringW
= (void *)GetProcAddress(hDll
, "RegLoadMUIStringW");
382 if (pRegLoadMUIStringW
&&
383 !pRegLoadMUIStringW(hkey
, value
, buffer
, size
, NULL
, 0, NULL
))
390 /***********************************************************************
391 * TIME_GetSpecificTimeZoneInfo
393 * Returns time zone information for the given time zone and year.
396 * key_name [in] The time zone name.
397 * year [in] The year, if Dynamic DST is used.
398 * dynamic [in] Whether to use Dynamic DST.
399 * result [out] The time zone information.
402 * TRUE if successful.
404 static BOOL
TIME_GetSpecificTimeZoneInfo( const WCHAR
*key_name
, WORD year
,
405 BOOL dynamic
, DYNAMIC_TIME_ZONE_INFORMATION
*tzinfo
)
407 static const WCHAR Dynamic_DstW
[] = { 'D','y','n','a','m','i','c',' ','D','S','T',0 };
408 static const WCHAR fmtW
[] = { '%','d',0 };
409 static const WCHAR stdW
[] = { 'S','t','d',0 };
410 static const WCHAR dltW
[] = { 'D','l','t',0 };
411 static const WCHAR tziW
[] = { 'T','Z','I',0 };
412 HANDLE time_zone_key
, dynamic_dst_key
;
413 OBJECT_ATTRIBUTES attr
;
414 UNICODE_STRING nameW
;
416 BOOL got_reg_data
= FALSE
;
426 if (!TIME_GetSpecificTimeZoneKey( key_name
, &time_zone_key
))
429 if (!reg_load_mui_string( time_zone_key
, mui_stdW
, tzinfo
->StandardName
, sizeof(tzinfo
->StandardName
) ) &&
430 !reg_query_value( time_zone_key
, stdW
, REG_SZ
, tzinfo
->StandardName
, sizeof(tzinfo
->StandardName
) ))
432 NtClose( time_zone_key
);
436 if (!reg_load_mui_string( time_zone_key
, mui_dltW
, tzinfo
->DaylightName
, sizeof(tzinfo
->DaylightName
) ) &&
437 !reg_query_value( time_zone_key
, dltW
, REG_SZ
, tzinfo
->DaylightName
, sizeof(tzinfo
->DaylightName
) ))
439 NtClose( time_zone_key
);
443 lstrcpyW(tzinfo
->TimeZoneKeyName
, key_name
);
447 attr
.Length
= sizeof(attr
);
448 attr
.RootDirectory
= time_zone_key
;
449 attr
.ObjectName
= &nameW
;
451 attr
.SecurityDescriptor
= NULL
;
452 attr
.SecurityQualityOfService
= NULL
;
453 RtlInitUnicodeString( &nameW
, Dynamic_DstW
);
454 if (!NtOpenKey( &dynamic_dst_key
, KEY_READ
, &attr
))
456 sprintfW( yearW
, fmtW
, year
);
457 got_reg_data
= reg_query_value( dynamic_dst_key
, yearW
, REG_BINARY
, &tz_data
, sizeof(tz_data
) );
459 NtClose( dynamic_dst_key
);
465 if (!reg_query_value( time_zone_key
, tziW
, REG_BINARY
, &tz_data
, sizeof(tz_data
) ))
467 NtClose( time_zone_key
);
472 tzinfo
->Bias
= tz_data
.bias
;
473 tzinfo
->StandardBias
= tz_data
.std_bias
;
474 tzinfo
->DaylightBias
= tz_data
.dlt_bias
;
475 tzinfo
->StandardDate
= tz_data
.std_date
;
476 tzinfo
->DaylightDate
= tz_data
.dlt_date
;
478 tzinfo
->DynamicDaylightTimeDisabled
= !dynamic
;
480 NtClose( time_zone_key
);
486 /***********************************************************************
487 * SetLocalTime (KERNEL32.@)
489 * Set the local time using current time zone and daylight
493 * systime [in] The desired local time.
496 * Success: TRUE. The time was set.
497 * Failure: FALSE, if the time was invalid or caller does not have
498 * permission to change the time.
500 BOOL WINAPI
SetLocalTime( const SYSTEMTIME
*systime
)
503 LARGE_INTEGER st
, st2
;
506 if( !SystemTimeToFileTime( systime
, &ft
))
508 st
.u
.LowPart
= ft
.dwLowDateTime
;
509 st
.u
.HighPart
= ft
.dwHighDateTime
;
510 RtlLocalTimeToSystemTime( &st
, &st2
);
512 if ((status
= NtSetSystemTime(&st2
, NULL
)))
513 SetLastError( RtlNtStatusToDosError(status
) );
518 /***********************************************************************
519 * GetSystemTimeAdjustment (KERNEL32.@)
521 * Get the period between clock interrupts and the amount the clock
522 * is adjusted each interrupt so as to keep it in sync with an external source.
525 * lpTimeAdjustment [out] The clock adjustment per interrupt in 100's of nanoseconds.
526 * lpTimeIncrement [out] The time between clock interrupts in 100's of nanoseconds.
527 * lpTimeAdjustmentDisabled [out] The clock synchronisation has been disabled.
533 * Only the special case of disabled time adjustments is supported.
535 BOOL WINAPI
GetSystemTimeAdjustment( PDWORD lpTimeAdjustment
, PDWORD lpTimeIncrement
,
536 PBOOL lpTimeAdjustmentDisabled
)
538 *lpTimeAdjustment
= 0;
539 *lpTimeIncrement
= 10000000 / sysconf(_SC_CLK_TCK
);
540 *lpTimeAdjustmentDisabled
= TRUE
;
545 /***********************************************************************
546 * SetSystemTime (KERNEL32.@)
548 * Set the system time in utc.
551 * systime [in] The desired system time.
554 * Success: TRUE. The time was set.
555 * Failure: FALSE, if the time was invalid or caller does not have
556 * permission to change the time.
558 BOOL WINAPI
SetSystemTime( const SYSTEMTIME
*systime
)
564 if( !SystemTimeToFileTime( systime
, &ft
))
566 t
.u
.LowPart
= ft
.dwLowDateTime
;
567 t
.u
.HighPart
= ft
.dwHighDateTime
;
568 if ((status
= NtSetSystemTime(&t
, NULL
)))
569 SetLastError( RtlNtStatusToDosError(status
) );
573 /***********************************************************************
574 * SetSystemTimeAdjustment (KERNEL32.@)
576 * Enables or disables the timing adjustments to the system's clock.
579 * dwTimeAdjustment [in] Number of units to add per clock interrupt.
580 * bTimeAdjustmentDisabled [in] Adjustment mode.
586 BOOL WINAPI
SetSystemTimeAdjustment( DWORD dwTimeAdjustment
, BOOL bTimeAdjustmentDisabled
)
588 /* Fake function for now... */
589 FIXME("(%08x,%d): stub !\n", dwTimeAdjustment
, bTimeAdjustmentDisabled
);
593 /***********************************************************************
594 * GetTimeZoneInformation (KERNEL32.@)
596 * Get information about the current local time zone.
599 * tzinfo [out] Destination for time zone information.
602 * TIME_ZONE_ID_INVALID An error occurred
603 * TIME_ZONE_ID_UNKNOWN There are no transition time known
604 * TIME_ZONE_ID_STANDARD Current time is standard time
605 * TIME_ZONE_ID_DAYLIGHT Current time is daylight savings time
607 DWORD WINAPI
GetTimeZoneInformation( LPTIME_ZONE_INFORMATION ret
)
609 DYNAMIC_TIME_ZONE_INFORMATION tzinfo
;
612 time_zone_id
= GetDynamicTimeZoneInformation( &tzinfo
);
613 memcpy( ret
, &tzinfo
, sizeof(*ret
) );
617 /***********************************************************************
618 * GetTimeZoneInformationForYear (KERNEL32.@)
620 BOOL WINAPI
GetTimeZoneInformationForYear( USHORT wYear
,
621 PDYNAMIC_TIME_ZONE_INFORMATION pdtzi
, LPTIME_ZONE_INFORMATION ptzi
)
623 DYNAMIC_TIME_ZONE_INFORMATION local_dtzi
, result
;
627 if (GetDynamicTimeZoneInformation(&local_dtzi
) == TIME_ZONE_ID_INVALID
)
632 if (!TIME_GetSpecificTimeZoneInfo(pdtzi
->TimeZoneKeyName
, wYear
,
633 !pdtzi
->DynamicDaylightTimeDisabled
, &result
))
636 memcpy(ptzi
, &result
, sizeof(*ptzi
));
641 /***********************************************************************
642 * SetTimeZoneInformation (KERNEL32.@)
644 * Change the settings of the current local time zone.
647 * tzinfo [in] The new time zone.
650 * Success: TRUE. The time zone was updated with the settings from tzinfo.
653 BOOL WINAPI
SetTimeZoneInformation( const TIME_ZONE_INFORMATION
*tzinfo
)
656 status
= RtlSetTimeZoneInformation( (const RTL_TIME_ZONE_INFORMATION
*)tzinfo
);
657 if ( status
!= STATUS_SUCCESS
)
658 SetLastError( RtlNtStatusToDosError(status
) );
662 /***********************************************************************
663 * SystemTimeToTzSpecificLocalTime (KERNEL32.@)
665 * Convert a utc system time to a local time in a given time zone.
668 * lpTimeZoneInformation [in] The desired time zone.
669 * lpUniversalTime [in] The utc time to base local time on.
670 * lpLocalTime [out] The local time in the time zone.
673 * Success: TRUE. lpLocalTime contains the converted time
677 BOOL WINAPI
SystemTimeToTzSpecificLocalTime(
678 const TIME_ZONE_INFORMATION
*lpTimeZoneInformation
,
679 const SYSTEMTIME
*lpUniversalTime
, LPSYSTEMTIME lpLocalTime
)
684 TIME_ZONE_INFORMATION tzinfo
;
686 if (lpTimeZoneInformation
!= NULL
)
688 tzinfo
= *lpTimeZoneInformation
;
692 RtlQueryTimeZoneInformation((RTL_TIME_ZONE_INFORMATION
*)&tzinfo
);
695 if (!SystemTimeToFileTime(lpUniversalTime
, &ft
))
697 FILETIME2LL( &ft
, llTime
)
698 if (!TIME_GetTimezoneBias(&tzinfo
, &ft
, FALSE
, &lBias
))
700 /* convert minutes to 100-nanoseconds-ticks */
701 llTime
-= (LONGLONG
)lBias
* 600000000;
702 LL2FILETIME( llTime
, &ft
)
704 return FileTimeToSystemTime(&ft
, lpLocalTime
);
708 /***********************************************************************
709 * TzSpecificLocalTimeToSystemTime (KERNEL32.@)
711 * Converts a local time to a time in utc.
714 * lpTimeZoneInformation [in] The desired time zone.
715 * lpLocalTime [in] The local time.
716 * lpUniversalTime [out] The calculated utc time.
719 * Success: TRUE. lpUniversalTime contains the converted time.
722 BOOL WINAPI
TzSpecificLocalTimeToSystemTime(
723 const TIME_ZONE_INFORMATION
*lpTimeZoneInformation
,
724 const SYSTEMTIME
*lpLocalTime
, LPSYSTEMTIME lpUniversalTime
)
729 TIME_ZONE_INFORMATION tzinfo
;
731 if (lpTimeZoneInformation
!= NULL
)
733 tzinfo
= *lpTimeZoneInformation
;
737 RtlQueryTimeZoneInformation((RTL_TIME_ZONE_INFORMATION
*)&tzinfo
);
740 if (!SystemTimeToFileTime(lpLocalTime
, &ft
))
743 if (!TIME_GetTimezoneBias(&tzinfo
, &ft
, TRUE
, &lBias
))
745 /* convert minutes to 100-nanoseconds-ticks */
746 t
+= (LONGLONG
)lBias
* 600000000;
748 return FileTimeToSystemTime(&ft
, lpUniversalTime
);
752 /***********************************************************************
753 * GetSystemTimeAsFileTime (KERNEL32.@)
755 * Get the current time in utc format.
760 VOID WINAPI
GetSystemTimeAsFileTime(
761 LPFILETIME time
) /* [out] Destination for the current utc time */
764 NtQuerySystemTime( &t
);
765 time
->dwLowDateTime
= t
.u
.LowPart
;
766 time
->dwHighDateTime
= t
.u
.HighPart
;
770 /***********************************************************************
771 * GetSystemTimePreciseAsFileTime (KERNEL32.@)
773 * Get the current time in utc format, with <1 us precision.
778 VOID WINAPI
GetSystemTimePreciseAsFileTime(
779 LPFILETIME time
) /* [out] Destination for the current utc time */
781 GetSystemTimeAsFileTime(time
);
785 /*********************************************************************
786 * TIME_ClockTimeToFileTime (olorin@fandra.org, 20-Sep-1998)
788 * Used by GetProcessTimes to convert clock_t into FILETIME.
790 * Differences to UnixTimeToFileTime:
791 * 1) Divided by CLK_TCK
792 * 2) Time is relative. There is no 'starting date', so there is
793 * no need for offset correction, like in UnixTimeToFileTime
795 static void TIME_ClockTimeToFileTime(clock_t unix_time
, LPFILETIME filetime
)
797 long clocksPerSec
= sysconf(_SC_CLK_TCK
);
798 ULONGLONG secs
= (ULONGLONG
)unix_time
* 10000000 / clocksPerSec
;
799 filetime
->dwLowDateTime
= (DWORD
)secs
;
800 filetime
->dwHighDateTime
= (DWORD
)(secs
>> 32);
803 /***********************************************************************
804 * TIMEZONE_InitRegistry
806 * Update registry contents on startup if the user timezone has changed.
807 * This simulates the action of the Windows control panel.
809 void TIMEZONE_InitRegistry(void)
811 static const WCHAR timezoneInformationW
[] = {
812 'M','a','c','h','i','n','e','\\','S','y','s','t','e','m','\\',
813 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\',
814 'C','o','n','t','r','o','l','\\',
815 'T','i','m','e','Z','o','n','e','I','n','f','o','r','m','a','t','i','o','n','\0'
817 static const WCHAR standardNameW
[] = {'S','t','a','n','d','a','r','d','N','a','m','e','\0'};
818 static const WCHAR timezoneKeyNameW
[] = {'T','i','m','e','Z','o','n','e','K','e','y','N','a','m','e','\0'};
819 DYNAMIC_TIME_ZONE_INFORMATION tzinfo
;
821 OBJECT_ATTRIBUTES attr
;
825 tzid
= GetDynamicTimeZoneInformation(&tzinfo
);
826 if (tzid
== TIME_ZONE_ID_INVALID
) return;
828 RtlInitUnicodeString(&name
, timezoneInformationW
);
829 InitializeObjectAttributes(&attr
, &name
, 0, 0, NULL
);
830 if (NtCreateKey(&hkey
, KEY_ALL_ACCESS
, &attr
, 0, NULL
, 0, NULL
) != STATUS_SUCCESS
) return;
832 RtlInitUnicodeString(&name
, standardNameW
);
833 NtSetValueKey(hkey
, &name
, 0, REG_SZ
, tzinfo
.StandardName
,
834 (strlenW(tzinfo
.StandardName
) + 1) * sizeof(WCHAR
));
836 RtlInitUnicodeString(&name
, timezoneKeyNameW
);
837 NtSetValueKey(hkey
, &name
, 0, REG_SZ
, tzinfo
.TimeZoneKeyName
,
838 (strlenW(tzinfo
.TimeZoneKeyName
) + 1) * sizeof(WCHAR
));
843 /*********************************************************************
844 * GetProcessTimes (KERNEL32.@)
846 * Get the user and kernel execution times of a process,
847 * along with the creation and exit times if known.
850 * hprocess [in] The process to be queried.
851 * lpCreationTime [out] The creation time of the process.
852 * lpExitTime [out] The exit time of the process if exited.
853 * lpKernelTime [out] The time spent in kernel routines in 100's of nanoseconds.
854 * lpUserTime [out] The time spent in user routines in 100's of nanoseconds.
861 * Would be nice to subtract the cpu time used by Wine at startup.
862 * Also, there is a need to separate times used by different applications.
865 * KernelTime and UserTime are always for the current process
867 BOOL WINAPI
GetProcessTimes( HANDLE hprocess
, LPFILETIME lpCreationTime
,
868 LPFILETIME lpExitTime
, LPFILETIME lpKernelTime
, LPFILETIME lpUserTime
)
871 KERNEL_USER_TIMES pti
;
874 TIME_ClockTimeToFileTime(tms
.tms_utime
,lpUserTime
);
875 TIME_ClockTimeToFileTime(tms
.tms_stime
,lpKernelTime
);
876 if (NtQueryInformationProcess( hprocess
, ProcessTimes
, &pti
, sizeof(pti
), NULL
))
878 LL2FILETIME( pti
.CreateTime
.QuadPart
, lpCreationTime
);
879 LL2FILETIME( pti
.ExitTime
.QuadPart
, lpExitTime
);
883 /*********************************************************************
884 * GetCalendarInfoA (KERNEL32.@)
887 int WINAPI
GetCalendarInfoA(LCID lcid
, CALID Calendar
, CALTYPE CalType
,
888 LPSTR lpCalData
, int cchData
, LPDWORD lpValue
)
890 int ret
, cchDataW
= cchData
;
891 LPWSTR lpCalDataW
= NULL
;
893 if (NLS_IsUnicodeOnlyLcid(lcid
))
895 SetLastError(ERROR_INVALID_PARAMETER
);
899 if (!cchData
&& !(CalType
& CAL_RETURN_NUMBER
))
900 cchDataW
= GetCalendarInfoW(lcid
, Calendar
, CalType
, NULL
, 0, NULL
);
901 if (!(lpCalDataW
= HeapAlloc(GetProcessHeap(), 0, cchDataW
*sizeof(WCHAR
))))
904 ret
= GetCalendarInfoW(lcid
, Calendar
, CalType
, lpCalDataW
, cchDataW
, lpValue
);
905 if(ret
&& lpCalDataW
&& lpCalData
)
906 ret
= WideCharToMultiByte(CP_ACP
, 0, lpCalDataW
, -1, lpCalData
, cchData
, NULL
, NULL
);
907 else if (CalType
& CAL_RETURN_NUMBER
)
908 ret
*= sizeof(WCHAR
);
909 HeapFree(GetProcessHeap(), 0, lpCalDataW
);
914 /*********************************************************************
915 * GetCalendarInfoW (KERNEL32.@)
918 int WINAPI
GetCalendarInfoW(LCID Locale
, CALID Calendar
, CALTYPE CalType
,
919 LPWSTR lpCalData
, int cchData
, LPDWORD lpValue
)
921 static const LCTYPE caltype_lctype_map
[] = {
923 0, /* CAL_ICALINTVALUE */
924 0, /* CAL_SCALNAME */
925 0, /* CAL_IYEAROFFSETRANGE */
926 0, /* CAL_SERASTRING */
936 LOCALE_SABBREVDAYNAME1
,
937 LOCALE_SABBREVDAYNAME2
,
938 LOCALE_SABBREVDAYNAME3
,
939 LOCALE_SABBREVDAYNAME4
,
940 LOCALE_SABBREVDAYNAME5
,
941 LOCALE_SABBREVDAYNAME6
,
942 LOCALE_SABBREVDAYNAME7
,
956 LOCALE_SABBREVMONTHNAME1
,
957 LOCALE_SABBREVMONTHNAME2
,
958 LOCALE_SABBREVMONTHNAME3
,
959 LOCALE_SABBREVMONTHNAME4
,
960 LOCALE_SABBREVMONTHNAME5
,
961 LOCALE_SABBREVMONTHNAME6
,
962 LOCALE_SABBREVMONTHNAME7
,
963 LOCALE_SABBREVMONTHNAME8
,
964 LOCALE_SABBREVMONTHNAME9
,
965 LOCALE_SABBREVMONTHNAME10
,
966 LOCALE_SABBREVMONTHNAME11
,
967 LOCALE_SABBREVMONTHNAME12
,
968 LOCALE_SABBREVMONTHNAME13
,
970 0, /* CAL_ITWODIGITYEARMAX */
971 LOCALE_SSHORTESTDAYNAME1
,
972 LOCALE_SSHORTESTDAYNAME2
,
973 LOCALE_SSHORTESTDAYNAME3
,
974 LOCALE_SSHORTESTDAYNAME4
,
975 LOCALE_SSHORTESTDAYNAME5
,
976 LOCALE_SSHORTESTDAYNAME6
,
977 LOCALE_SSHORTESTDAYNAME7
,
979 0, /* CAL_SABBREVERASTRING */
981 DWORD localeflags
= 0;
984 if (CalType
& CAL_NOUSEROVERRIDE
)
985 FIXME("flag CAL_NOUSEROVERRIDE used, not fully implemented\n");
986 if (CalType
& CAL_USE_CP_ACP
)
987 FIXME("flag CAL_USE_CP_ACP used, not fully implemented\n");
989 if (CalType
& CAL_RETURN_NUMBER
) {
992 SetLastError( ERROR_INVALID_PARAMETER
);
995 if (lpCalData
!= NULL
)
996 WARN("lpCalData not NULL (%p) when it should!\n", lpCalData
);
998 WARN("cchData not 0 (%d) when it should!\n", cchData
);
1000 if (lpValue
!= NULL
)
1001 WARN("lpValue not NULL (%p) when it should!\n", lpValue
);
1004 /* FIXME: No verification is made yet wrt Locale
1005 * for the CALTYPES not requiring GetLocaleInfoA */
1007 calinfo
= CalType
& 0xffff;
1009 if (CalType
& CAL_RETURN_GENITIVE_NAMES
)
1010 localeflags
|= LOCALE_RETURN_GENITIVE_NAMES
;
1013 case CAL_ICALINTVALUE
:
1014 if (CalType
& CAL_RETURN_NUMBER
)
1015 return GetLocaleInfoW(Locale
, LOCALE_RETURN_NUMBER
| LOCALE_ICALENDARTYPE
,
1016 (LPWSTR
)lpValue
, 2);
1017 return GetLocaleInfoW(Locale
, LOCALE_ICALENDARTYPE
, lpCalData
, cchData
);
1019 FIXME("Unimplemented caltype %d\n", calinfo
);
1020 if (lpCalData
) *lpCalData
= 0;
1022 case CAL_IYEAROFFSETRANGE
:
1023 FIXME("Unimplemented caltype %d\n", calinfo
);
1025 case CAL_SERASTRING
:
1026 FIXME("Unimplemented caltype %d\n", calinfo
);
1028 case CAL_SSHORTDATE
:
1037 case CAL_SABBREVDAYNAME1
:
1038 case CAL_SABBREVDAYNAME2
:
1039 case CAL_SABBREVDAYNAME3
:
1040 case CAL_SABBREVDAYNAME4
:
1041 case CAL_SABBREVDAYNAME5
:
1042 case CAL_SABBREVDAYNAME6
:
1043 case CAL_SABBREVDAYNAME7
:
1044 case CAL_SMONTHNAME1
:
1045 case CAL_SMONTHNAME2
:
1046 case CAL_SMONTHNAME3
:
1047 case CAL_SMONTHNAME4
:
1048 case CAL_SMONTHNAME5
:
1049 case CAL_SMONTHNAME6
:
1050 case CAL_SMONTHNAME7
:
1051 case CAL_SMONTHNAME8
:
1052 case CAL_SMONTHNAME9
:
1053 case CAL_SMONTHNAME10
:
1054 case CAL_SMONTHNAME11
:
1055 case CAL_SMONTHNAME12
:
1056 case CAL_SMONTHNAME13
:
1057 case CAL_SABBREVMONTHNAME1
:
1058 case CAL_SABBREVMONTHNAME2
:
1059 case CAL_SABBREVMONTHNAME3
:
1060 case CAL_SABBREVMONTHNAME4
:
1061 case CAL_SABBREVMONTHNAME5
:
1062 case CAL_SABBREVMONTHNAME6
:
1063 case CAL_SABBREVMONTHNAME7
:
1064 case CAL_SABBREVMONTHNAME8
:
1065 case CAL_SABBREVMONTHNAME9
:
1066 case CAL_SABBREVMONTHNAME10
:
1067 case CAL_SABBREVMONTHNAME11
:
1068 case CAL_SABBREVMONTHNAME12
:
1069 case CAL_SABBREVMONTHNAME13
:
1070 case CAL_SYEARMONTH
:
1071 case CAL_SSHORTESTDAYNAME1
:
1072 case CAL_SSHORTESTDAYNAME2
:
1073 case CAL_SSHORTESTDAYNAME3
:
1074 case CAL_SSHORTESTDAYNAME4
:
1075 case CAL_SSHORTESTDAYNAME5
:
1076 case CAL_SSHORTESTDAYNAME6
:
1077 case CAL_SSHORTESTDAYNAME7
:
1078 return GetLocaleInfoW(Locale
, caltype_lctype_map
[calinfo
] | localeflags
, lpCalData
, cchData
);
1079 case CAL_ITWODIGITYEARMAX
:
1080 if (CalType
& CAL_RETURN_NUMBER
)
1082 *lpValue
= CALINFO_MAX_YEAR
;
1083 return sizeof(DWORD
) / sizeof(WCHAR
);
1087 static const WCHAR fmtW
[] = {'%','u',0};
1089 int ret
= snprintfW( buffer
, 10, fmtW
, CALINFO_MAX_YEAR
) + 1;
1090 if (!lpCalData
) return ret
;
1093 strcpyW( lpCalData
, buffer
);
1096 SetLastError( ERROR_INSUFFICIENT_BUFFER
);
1101 FIXME("Unimplemented caltype %d\n", calinfo
);
1103 case CAL_SABBREVERASTRING
:
1104 FIXME("Unimplemented caltype %d\n", calinfo
);
1107 FIXME("Unknown caltype %d\n", calinfo
);
1108 SetLastError(ERROR_INVALID_FLAGS
);
1114 /*********************************************************************
1115 * GetCalendarInfoEx (KERNEL32.@)
1117 int WINAPI
GetCalendarInfoEx(LPCWSTR locale
, CALID calendar
, LPCWSTR lpReserved
, CALTYPE caltype
,
1118 LPWSTR data
, int len
, DWORD
*value
)
1122 LCID lcid
= LocaleNameToLCID(locale
, 0);
1124 FIXME("(%s, %d, %p, 0x%08x, %p, %d, %p): semi-stub\n", debugstr_w(locale
), calendar
, lpReserved
, caltype
,
1126 return GetCalendarInfoW(lcid
, calendar
, caltype
, data
, len
, value
);
1129 /*********************************************************************
1130 * SetCalendarInfoA (KERNEL32.@)
1133 int WINAPI
SetCalendarInfoA(LCID Locale
, CALID Calendar
, CALTYPE CalType
, LPCSTR lpCalData
)
1135 FIXME("(%08x,%08x,%08x,%s): stub\n",
1136 Locale
, Calendar
, CalType
, debugstr_a(lpCalData
));
1140 /*********************************************************************
1141 * SetCalendarInfoW (KERNEL32.@)
1145 int WINAPI
SetCalendarInfoW(LCID Locale
, CALID Calendar
, CALTYPE CalType
, LPCWSTR lpCalData
)
1147 FIXME("(%08x,%08x,%08x,%s): stub\n",
1148 Locale
, Calendar
, CalType
, debugstr_w(lpCalData
));
1152 /*********************************************************************
1153 * LocalFileTimeToFileTime (KERNEL32.@)
1155 BOOL WINAPI
LocalFileTimeToFileTime( const FILETIME
*localft
, LPFILETIME utcft
)
1158 LARGE_INTEGER local
, utc
;
1160 local
.u
.LowPart
= localft
->dwLowDateTime
;
1161 local
.u
.HighPart
= localft
->dwHighDateTime
;
1162 if (!(status
= RtlLocalTimeToSystemTime( &local
, &utc
)))
1164 utcft
->dwLowDateTime
= utc
.u
.LowPart
;
1165 utcft
->dwHighDateTime
= utc
.u
.HighPart
;
1167 else SetLastError( RtlNtStatusToDosError(status
) );
1172 /*********************************************************************
1173 * FileTimeToLocalFileTime (KERNEL32.@)
1175 BOOL WINAPI
FileTimeToLocalFileTime( const FILETIME
*utcft
, LPFILETIME localft
)
1178 LARGE_INTEGER local
, utc
;
1180 utc
.u
.LowPart
= utcft
->dwLowDateTime
;
1181 utc
.u
.HighPart
= utcft
->dwHighDateTime
;
1182 if (!(status
= RtlSystemTimeToLocalTime( &utc
, &local
)))
1184 localft
->dwLowDateTime
= local
.u
.LowPart
;
1185 localft
->dwHighDateTime
= local
.u
.HighPart
;
1187 else SetLastError( RtlNtStatusToDosError(status
) );
1192 /*********************************************************************
1193 * FileTimeToSystemTime (KERNEL32.@)
1195 BOOL WINAPI
FileTimeToSystemTime( const FILETIME
*ft
, LPSYSTEMTIME syst
)
1200 t
.u
.LowPart
= ft
->dwLowDateTime
;
1201 t
.u
.HighPart
= ft
->dwHighDateTime
;
1202 RtlTimeToTimeFields(&t
, &tf
);
1204 syst
->wYear
= tf
.Year
;
1205 syst
->wMonth
= tf
.Month
;
1206 syst
->wDay
= tf
.Day
;
1207 syst
->wHour
= tf
.Hour
;
1208 syst
->wMinute
= tf
.Minute
;
1209 syst
->wSecond
= tf
.Second
;
1210 syst
->wMilliseconds
= tf
.Milliseconds
;
1211 syst
->wDayOfWeek
= tf
.Weekday
;
1215 /*********************************************************************
1216 * SystemTimeToFileTime (KERNEL32.@)
1218 BOOL WINAPI
SystemTimeToFileTime( const SYSTEMTIME
*syst
, LPFILETIME ft
)
1223 tf
.Year
= syst
->wYear
;
1224 tf
.Month
= syst
->wMonth
;
1225 tf
.Day
= syst
->wDay
;
1226 tf
.Hour
= syst
->wHour
;
1227 tf
.Minute
= syst
->wMinute
;
1228 tf
.Second
= syst
->wSecond
;
1229 tf
.Milliseconds
= syst
->wMilliseconds
;
1231 if( !RtlTimeFieldsToTime(&tf
, &t
)) {
1232 SetLastError( ERROR_INVALID_PARAMETER
);
1235 ft
->dwLowDateTime
= t
.u
.LowPart
;
1236 ft
->dwHighDateTime
= t
.u
.HighPart
;
1240 /*********************************************************************
1241 * CompareFileTime (KERNEL32.@)
1243 * Compare two FILETIME's to each other.
1247 * y [I] time to compare to x
1250 * -1, 0, or 1 indicating that x is less than, equal to, or greater
1251 * than y respectively.
1253 INT WINAPI
CompareFileTime( const FILETIME
*x
, const FILETIME
*y
)
1255 if (!x
|| !y
) return -1;
1257 if (x
->dwHighDateTime
> y
->dwHighDateTime
)
1259 if (x
->dwHighDateTime
< y
->dwHighDateTime
)
1261 if (x
->dwLowDateTime
> y
->dwLowDateTime
)
1263 if (x
->dwLowDateTime
< y
->dwLowDateTime
)
1268 /*********************************************************************
1269 * GetLocalTime (KERNEL32.@)
1271 * Get the current local time.
1274 * systime [O] Destination for current time.
1279 VOID WINAPI
GetLocalTime(LPSYSTEMTIME systime
)
1282 LARGE_INTEGER ft
, ft2
;
1284 NtQuerySystemTime(&ft
);
1285 RtlSystemTimeToLocalTime(&ft
, &ft2
);
1286 lft
.dwLowDateTime
= ft2
.u
.LowPart
;
1287 lft
.dwHighDateTime
= ft2
.u
.HighPart
;
1288 FileTimeToSystemTime(&lft
, systime
);
1291 /*********************************************************************
1292 * GetSystemTime (KERNEL32.@)
1294 * Get the current system time.
1297 * systime [O] Destination for current time.
1302 VOID WINAPI
GetSystemTime(LPSYSTEMTIME systime
)
1307 NtQuerySystemTime(&t
);
1308 ft
.dwLowDateTime
= t
.u
.LowPart
;
1309 ft
.dwHighDateTime
= t
.u
.HighPart
;
1310 FileTimeToSystemTime(&ft
, systime
);
1313 /*********************************************************************
1314 * GetDaylightFlag (KERNEL32.@)
1316 * Specifies if daylight savings time is in operation.
1319 * This function is called from the Win98's control applet timedate.cpl.
1322 * TRUE if daylight savings time is in operation.
1325 BOOL WINAPI
GetDaylightFlag(void)
1327 TIME_ZONE_INFORMATION tzinfo
;
1328 RtlQueryTimeZoneInformation((RTL_TIME_ZONE_INFORMATION
*)&tzinfo
);
1329 return (TIME_ZoneID(&tzinfo
) == TIME_ZONE_ID_DAYLIGHT
);
1332 /***********************************************************************
1333 * DosDateTimeToFileTime (KERNEL32.@)
1335 BOOL WINAPI
DosDateTimeToFileTime( WORD fatdate
, WORD fattime
, LPFILETIME ft
)
1340 time_t time1
, time2
;
1343 newtm
.tm_sec
= (fattime
& 0x1f) * 2;
1344 newtm
.tm_min
= (fattime
>> 5) & 0x3f;
1345 newtm
.tm_hour
= (fattime
>> 11);
1346 newtm
.tm_mday
= (fatdate
& 0x1f);
1347 newtm
.tm_mon
= ((fatdate
>> 5) & 0x0f) - 1;
1348 newtm
.tm_year
= (fatdate
>> 9) + 80;
1349 newtm
.tm_isdst
= -1;
1351 RtlSecondsSince1970ToTime( timegm(&newtm
), (LARGE_INTEGER
*)ft
);
1353 time1
= mktime(&newtm
);
1354 gtm
= gmtime(&time1
);
1355 time2
= mktime(gtm
);
1356 RtlSecondsSince1970ToTime( 2*time1
-time2
, (LARGE_INTEGER
*)ft
);
1362 /***********************************************************************
1363 * FileTimeToDosDateTime (KERNEL32.@)
1365 BOOL WINAPI
FileTimeToDosDateTime( const FILETIME
*ft
, LPWORD fatdate
,
1373 if (!fatdate
|| !fattime
)
1375 SetLastError(ERROR_INVALID_PARAMETER
);
1378 li
.u
.LowPart
= ft
->dwLowDateTime
;
1379 li
.u
.HighPart
= ft
->dwHighDateTime
;
1380 if (!RtlTimeToSecondsSince1970( &li
, &t
))
1382 SetLastError(ERROR_INVALID_PARAMETER
);
1386 tm
= gmtime( &unixtime
);
1387 *fattime
= (tm
->tm_hour
<< 11) + (tm
->tm_min
<< 5) + (tm
->tm_sec
/ 2);
1388 *fatdate
= ((tm
->tm_year
- 80) << 9) + ((tm
->tm_mon
+ 1) << 5) + tm
->tm_mday
;
1392 /*********************************************************************
1393 * GetSystemTimes (KERNEL32.@)
1395 * Retrieves system timing information
1398 * lpIdleTime [O] Destination for idle time.
1399 * lpKernelTime [O] Destination for kernel time.
1400 * lpUserTime [O] Destination for user time.
1403 * TRUE if success, FALSE otherwise.
1405 BOOL WINAPI
GetSystemTimes(LPFILETIME lpIdleTime
, LPFILETIME lpKernelTime
, LPFILETIME lpUserTime
)
1407 LARGE_INTEGER idle_time
, kernel_time
, user_time
;
1408 SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION
*sppi
;
1409 SYSTEM_BASIC_INFORMATION sbi
;
1414 TRACE("(%p,%p,%p)\n", lpIdleTime
, lpKernelTime
, lpUserTime
);
1416 status
= NtQuerySystemInformation( SystemBasicInformation
, &sbi
, sizeof(sbi
), &ret_size
);
1417 if (status
!= STATUS_SUCCESS
)
1419 SetLastError( RtlNtStatusToDosError(status
) );
1423 sppi
= HeapAlloc( GetProcessHeap(), 0,
1424 sizeof(SYSTEM_PROCESSOR_PERFORMANCE_INFORMATION
) * sbi
.NumberOfProcessors
);
1427 SetLastError( ERROR_OUTOFMEMORY
);
1431 status
= NtQuerySystemInformation( SystemProcessorPerformanceInformation
, sppi
, sizeof(*sppi
) * sbi
.NumberOfProcessors
,
1433 if (status
!= STATUS_SUCCESS
)
1435 HeapFree( GetProcessHeap(), 0, sppi
);
1436 SetLastError( RtlNtStatusToDosError(status
) );
1440 idle_time
.QuadPart
= 0;
1441 kernel_time
.QuadPart
= 0;
1442 user_time
.QuadPart
= 0;
1443 for (i
= 0; i
< sbi
.NumberOfProcessors
; i
++)
1445 idle_time
.QuadPart
+= sppi
[i
].IdleTime
.QuadPart
;
1446 kernel_time
.QuadPart
+= sppi
[i
].KernelTime
.QuadPart
;
1447 user_time
.QuadPart
+= sppi
[i
].UserTime
.QuadPart
;
1452 lpIdleTime
->dwLowDateTime
= idle_time
.u
.LowPart
;
1453 lpIdleTime
->dwHighDateTime
= idle_time
.u
.HighPart
;
1457 lpKernelTime
->dwLowDateTime
= kernel_time
.u
.LowPart
;
1458 lpKernelTime
->dwHighDateTime
= kernel_time
.u
.HighPart
;
1462 lpUserTime
->dwLowDateTime
= user_time
.u
.LowPart
;
1463 lpUserTime
->dwHighDateTime
= user_time
.u
.HighPart
;
1466 HeapFree( GetProcessHeap(), 0, sppi
);
1470 /***********************************************************************
1471 * GetDynamicTimeZoneInformation (KERNEL32.@)
1473 DWORD WINAPI
GetDynamicTimeZoneInformation(DYNAMIC_TIME_ZONE_INFORMATION
*tzinfo
)
1476 HANDLE time_zone_key
;
1478 status
= RtlQueryDynamicTimeZoneInformation( (RTL_DYNAMIC_TIME_ZONE_INFORMATION
*)tzinfo
);
1479 if ( status
!= STATUS_SUCCESS
)
1481 SetLastError( RtlNtStatusToDosError(status
) );
1482 return TIME_ZONE_ID_INVALID
;
1485 if (!TIME_GetSpecificTimeZoneKey( tzinfo
->TimeZoneKeyName
, &time_zone_key
))
1486 return TIME_ZONE_ID_INVALID
;
1487 reg_load_mui_string( time_zone_key
, mui_stdW
, tzinfo
->StandardName
, sizeof(tzinfo
->StandardName
) );
1488 reg_load_mui_string( time_zone_key
, mui_dltW
, tzinfo
->DaylightName
, sizeof(tzinfo
->DaylightName
) );
1489 NtClose( time_zone_key
);
1491 return TIME_ZoneID( (TIME_ZONE_INFORMATION
*)tzinfo
);
1494 /***********************************************************************
1495 * GetDynamicTimeZoneInformationEffectiveYears (KERNEL32.@)
1497 DWORD WINAPI
GetDynamicTimeZoneInformationEffectiveYears(DYNAMIC_TIME_ZONE_INFORMATION
*tzinfo
, DWORD
*first_year
, DWORD
*last_year
)
1499 FIXME("(%p, %p, %p): stub!\n", tzinfo
, first_year
, last_year
);
1500 return ERROR_FILE_NOT_FOUND
;
1503 /***********************************************************************
1504 * QueryProcessCycleTime (KERNEL32.@)
1506 BOOL WINAPI
QueryProcessCycleTime(HANDLE process
, PULONG64 cycle
)
1510 FIXME("(%p,%p): stub!\n", process
, cycle
);
1511 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1515 /***********************************************************************
1516 * QueryThreadCycleTime (KERNEL32.@)
1518 BOOL WINAPI
QueryThreadCycleTime(HANDLE thread
, PULONG64 cycle
)
1522 FIXME("(%p,%p): stub!\n", thread
, cycle
);
1523 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1527 /***********************************************************************
1528 * QueryUnbiasedInterruptTime (KERNEL32.@)
1530 BOOL WINAPI
QueryUnbiasedInterruptTime(ULONGLONG
*time
)
1532 TRACE("(%p)\n", time
);
1533 if (!time
) return FALSE
;
1534 RtlQueryUnbiasedInterruptTime(time
);