1 | /* $Id: time.cpp,v 1.18 2002-04-30 09:21:33 sandervl Exp $ */
|
---|
2 |
|
---|
3 | /*
|
---|
4 | * Win32 time/date API functions
|
---|
5 | *
|
---|
6 | * Copyright 1998 Sander van Leeuwen (sandervl@xs4all.nl)
|
---|
7 | * Copyright 1999 Christoph Bratschi (cbratschi@datacomm.ch)
|
---|
8 | *
|
---|
9 | * Copyright 1996 Alexandre Julliard
|
---|
10 | * Copyright 1995 Martin von Loewis
|
---|
11 | * Copyright 1998 David Lee Lambert
|
---|
12 |
|
---|
13 | *
|
---|
14 | * Project Odin Software License can be found in LICENSE.TXT
|
---|
15 | */
|
---|
16 |
|
---|
17 |
|
---|
18 | /*****************************************************************************
|
---|
19 | * Includes *
|
---|
20 | *****************************************************************************/
|
---|
21 |
|
---|
22 | #include <odin.h>
|
---|
23 | #include <odinwrap.h>
|
---|
24 | #include <os2sel.h>
|
---|
25 |
|
---|
26 | #include <os2win.h>
|
---|
27 |
|
---|
28 | #include <winnls.h>
|
---|
29 | #include "winuser.h"
|
---|
30 | #include <stdlib.h>
|
---|
31 | #include <string.h>
|
---|
32 | #include <stdio.h>
|
---|
33 | #include <time.h>
|
---|
34 | #include "unicode.h"
|
---|
35 |
|
---|
36 | #define DBG_LOCALLOG DBG_time
|
---|
37 | #include "dbglocal.h"
|
---|
38 |
|
---|
39 | /*****************************************************************************
|
---|
40 | * Defines *
|
---|
41 | *****************************************************************************/
|
---|
42 |
|
---|
43 | ODINDEBUGCHANNEL(KERNEL32-TIME)
|
---|
44 |
|
---|
45 |
|
---|
46 |
|
---|
47 | #define lstrcpynAtoW(unicode,ascii,asciilen) AsciiToUnicodeN(ascii,unicode,asciilen);
|
---|
48 |
|
---|
49 | #define WPRINTF_LEFTALIGN 0x0001 /* Align output on the left ('-' prefix) */
|
---|
50 | #define WPRINTF_PREFIX_HEX 0x0002 /* Prefix hex with 0x ('#' prefix) */
|
---|
51 | #define WPRINTF_ZEROPAD 0x0004 /* Pad with zeros ('0' prefix) */
|
---|
52 | #define WPRINTF_LONG 0x0008 /* Long arg ('l' prefix) */
|
---|
53 | #define WPRINTF_SHORT 0x0010 /* Short arg ('h' prefix) */
|
---|
54 | #define WPRINTF_UPPER_HEX 0x0020 /* Upper-case hex ('X' specifier) */
|
---|
55 | #define WPRINTF_WIDE 0x0040 /* Wide arg ('w' prefix) */
|
---|
56 |
|
---|
57 | typedef enum
|
---|
58 | {
|
---|
59 | WPR_UNKNOWN,
|
---|
60 | WPR_CHAR,
|
---|
61 | WPR_WCHAR,
|
---|
62 | WPR_STRING,
|
---|
63 | WPR_WSTRING,
|
---|
64 | WPR_SIGNED,
|
---|
65 | WPR_UNSIGNED,
|
---|
66 | WPR_HEXA
|
---|
67 | } WPRINTF_TYPE;
|
---|
68 |
|
---|
69 | typedef struct
|
---|
70 | {
|
---|
71 | UINT flags;
|
---|
72 | UINT width;
|
---|
73 | UINT precision;
|
---|
74 | WPRINTF_TYPE type;
|
---|
75 | } WPRINTF_FORMAT;
|
---|
76 |
|
---|
77 | typedef union {
|
---|
78 | WCHAR wchar_view;
|
---|
79 | CHAR char_view;
|
---|
80 | LPCSTR lpcstr_view;
|
---|
81 | LPCWSTR lpcwstr_view;
|
---|
82 | INT int_view;
|
---|
83 | } WPRINTF_DATA;
|
---|
84 |
|
---|
85 | static const CHAR null_stringA[] = "(null)";
|
---|
86 | static const WCHAR null_stringW[] = { '(', 'n', 'u', 'l', 'l', ')', 0 };
|
---|
87 |
|
---|
88 | //******************************************************************************
|
---|
89 | //******************************************************************************
|
---|
90 | void WIN32API GetLocalTime(LPSYSTEMTIME arg1)
|
---|
91 | {
|
---|
92 | O32_GetLocalTime(arg1);
|
---|
93 | }
|
---|
94 | //******************************************************************************
|
---|
95 | //******************************************************************************
|
---|
96 | BOOL WIN32API SetLocalTime(const SYSTEMTIME * arg1)
|
---|
97 | {
|
---|
98 | return O32_SetLocalTime(arg1);
|
---|
99 | }
|
---|
100 | //******************************************************************************
|
---|
101 | //******************************************************************************
|
---|
102 | BOOL WIN32API FileTimeToDosDateTime(const FILETIME * arg1, LPWORD arg2,
|
---|
103 | LPWORD arg3)
|
---|
104 | {
|
---|
105 | return O32_FileTimeToDosDateTime(arg1, arg2, arg3);
|
---|
106 | }
|
---|
107 |
|
---|
108 | //******************************************************************************
|
---|
109 | //******************************************************************************
|
---|
110 | BOOL WIN32API FileTimeToLocalFileTime(const FILETIME * utcft, LPFILETIME localft)
|
---|
111 | {
|
---|
112 | return O32_FileTimeToLocalFileTime(utcft,localft);
|
---|
113 | }
|
---|
114 | //******************************************************************************
|
---|
115 | //******************************************************************************
|
---|
116 | BOOL WIN32API LocalFileTimeToFileTime(const FILETIME * arg1, LPFILETIME arg2)
|
---|
117 | {
|
---|
118 | dprintf(("KERNEL32: LocalFileTimeToFileTime\n"));
|
---|
119 | return O32_LocalFileTimeToFileTime(arg1, arg2);
|
---|
120 | }
|
---|
121 | //******************************************************************************
|
---|
122 | //******************************************************************************
|
---|
123 | BOOL WIN32API FileTimeToSystemTime(const FILETIME * arg1, LPSYSTEMTIME arg2)
|
---|
124 | {
|
---|
125 | /* Another WGSS bug it expects not UCT on input but LocalTime! */
|
---|
126 | FILETIME dummy;
|
---|
127 | FileTimeToLocalFileTime(arg1,&dummy);
|
---|
128 | return O32_FileTimeToSystemTime(&dummy, arg2);
|
---|
129 | }
|
---|
130 | //******************************************************************************
|
---|
131 | //******************************************************************************
|
---|
132 | BOOL WIN32API DosDateTimeToFileTime(WORD arg1, WORD arg2, LPFILETIME arg3)
|
---|
133 | {
|
---|
134 | BOOL rc;
|
---|
135 | rc = O32_DosDateTimeToFileTime(arg1, arg2, arg3);
|
---|
136 | /* Bug in WGSS after that we must have UCT file time on return,
|
---|
137 | instead we have local! */
|
---|
138 | if (rc)
|
---|
139 | {
|
---|
140 | FILETIME dummy;
|
---|
141 | /* Convert it to UCT */
|
---|
142 | rc = LocalFileTimeToFileTime(arg3,&dummy);
|
---|
143 | memcpy(arg3,&dummy,sizeof(FILETIME));
|
---|
144 | }
|
---|
145 | return rc;
|
---|
146 | }
|
---|
147 | //******************************************************************************
|
---|
148 | //******************************************************************************
|
---|
149 | DWORD WIN32API GetTimeZoneInformation(LPTIME_ZONE_INFORMATION arg1)
|
---|
150 | {
|
---|
151 | return O32_GetTimeZoneInformation(arg1);
|
---|
152 | }
|
---|
153 | //******************************************************************************
|
---|
154 | //******************************************************************************
|
---|
155 | DWORD WIN32API GetTickCount(void)
|
---|
156 | {
|
---|
157 | //// dprintf(("KERNEL32: GetTickCount\n"));
|
---|
158 | return O32_GetTickCount();
|
---|
159 | }
|
---|
160 | //******************************************************************************
|
---|
161 | //******************************************************************************
|
---|
162 | void WIN32API GetSystemTime(LPSYSTEMTIME arg1)
|
---|
163 | {
|
---|
164 | O32_GetSystemTime(arg1);
|
---|
165 | }
|
---|
166 | //******************************************************************************
|
---|
167 | //******************************************************************************
|
---|
168 | BOOL WIN32API SystemTimeToFileTime(const SYSTEMTIME * arg1,
|
---|
169 | LPFILETIME arg2)
|
---|
170 | {
|
---|
171 | BOOL rc;
|
---|
172 | rc = O32_SystemTimeToFileTime(arg1, arg2);
|
---|
173 | /* Bug in WGSS after that we must have UCT file time on return,
|
---|
174 | instead we have local! */
|
---|
175 | if (rc)
|
---|
176 | {
|
---|
177 | FILETIME dummy;
|
---|
178 | /* Convert it to local */
|
---|
179 | rc = LocalFileTimeToFileTime(arg2,&dummy);
|
---|
180 | memcpy(arg2,&dummy,sizeof(FILETIME));
|
---|
181 | }
|
---|
182 | return rc;
|
---|
183 | }
|
---|
184 | //******************************************************************************
|
---|
185 | //******************************************************************************
|
---|
186 | BOOL WIN32API SystemTimeToTzSpecificLocalTime(LPTIME_ZONE_INFORMATION arg1,
|
---|
187 | LPSYSTEMTIME arg2,
|
---|
188 | LPSYSTEMTIME arg3)
|
---|
189 | {
|
---|
190 | return O32_SystemTimeToTzSpecificLocalTime(arg1, arg2, arg3);
|
---|
191 | }
|
---|
192 | //******************************************************************************
|
---|
193 | //******************************************************************************
|
---|
194 | BOOL WIN32API SetTimeZoneInformation(const LPTIME_ZONE_INFORMATION arg1)
|
---|
195 | {
|
---|
196 | return O32_SetTimeZoneInformation(arg1);
|
---|
197 | }
|
---|
198 | //******************************************************************************
|
---|
199 | //******************************************************************************
|
---|
200 | BOOL WIN32API SetSystemTime(const SYSTEMTIME * arg1)
|
---|
201 | {
|
---|
202 | return O32_SetSystemTime(arg1);
|
---|
203 | }
|
---|
204 | /*****************************************************************************
|
---|
205 | * Name : DWORD GetSystemTimeAsFileTime
|
---|
206 | * Purpose : The GetSystemTimeAsFileTime function obtains the current system
|
---|
207 | * date and time. The information is in Coordinated Universal Time (UTC) format.
|
---|
208 | * Parameters: LLPFILETIME lLPSYSTEMTIMEAsFileTime
|
---|
209 | * Variables :
|
---|
210 | * Result :
|
---|
211 | * Remark :
|
---|
212 | * Status : UNTESTED
|
---|
213 | *
|
---|
214 | * Author : Patrick Haller [Mon, 1998/06/15 08:00]
|
---|
215 | *****************************************************************************/
|
---|
216 |
|
---|
217 | VOID WIN32API GetSystemTimeAsFileTime(LPFILETIME lpSystemTimeAsFileTime)
|
---|
218 | {
|
---|
219 | FILETIME ft; /* code sequence from WIN32.HLP */
|
---|
220 | SYSTEMTIME st;
|
---|
221 |
|
---|
222 | dprintf(("KERNEL32: GetSystemTimeAsFileTime(%08xh)\n", lpSystemTimeAsFileTime));
|
---|
223 |
|
---|
224 | GetSystemTime(&st);
|
---|
225 | SystemTimeToFileTime(&st, &ft);
|
---|
226 | }
|
---|