Built a complete translation table for RtlNtStatusToDosError.
[wine] / win32 / time.c
1 /*
2  * Win32 kernel functions
3  *
4  * Copyright 1995 Martin von Loewis and Cameron Heide
5  */
6
7 #include <string.h>
8 #include <time.h>
9 #include <sys/time.h>
10 #include <unistd.h>
11 #include "file.h"
12 #include "winerror.h"
13 #include "debugtools.h"
14
15 DEFAULT_DEBUG_CHANNEL(win32)
16
17 /***********************************************************************
18  *              GetLocalTime            (KERNEL32.228)
19  */
20 VOID WINAPI GetLocalTime(LPSYSTEMTIME systime)
21 {
22     time_t local_time;
23     struct tm *local_tm;
24     struct timeval tv;
25
26     gettimeofday(&tv, NULL);
27     local_time = tv.tv_sec;
28     local_tm = localtime(&local_time);
29
30     systime->wYear = local_tm->tm_year + 1900;
31     systime->wMonth = local_tm->tm_mon + 1;
32     systime->wDayOfWeek = local_tm->tm_wday;
33     systime->wDay = local_tm->tm_mday;
34     systime->wHour = local_tm->tm_hour;
35     systime->wMinute = local_tm->tm_min;
36     systime->wSecond = local_tm->tm_sec;
37     systime->wMilliseconds = (tv.tv_usec / 1000) % 1000;
38 }
39
40
41 /***********************************************************************
42  *              SetLocalTime            (KERNEL32.655)
43  *
44  * FIXME: correct ? Is the timezone param of settimeofday() needed ?
45  * I don't have any docu about SetLocal/SystemTime(), argl...
46  */
47 BOOL WINAPI SetLocalTime(const SYSTEMTIME *systime)
48 {
49     struct timeval tv;
50     struct tm t;
51     time_t sec;
52
53     /* get the number of seconds */
54     t.tm_sec = systime->wSecond;
55     t.tm_min = systime->wMinute;
56     t.tm_hour = systime->wHour;
57     t.tm_mday = systime->wDay;
58     t.tm_mon = systime->wMonth;
59     t.tm_year = systime->wYear;
60     sec = mktime (&t);
61
62     /* set the new time */
63     tv.tv_sec = sec;
64     tv.tv_usec = systime->wMilliseconds * 1000;
65     return !settimeofday(&tv, NULL);
66 }
67
68
69 /***********************************************************************
70  *              GetSystemTime            (KERNEL32.285)
71  */
72 VOID WINAPI GetSystemTime(LPSYSTEMTIME systime)
73 {
74     time_t local_time;
75     struct tm *local_tm;
76     struct timeval tv;
77
78     gettimeofday(&tv, NULL);
79     local_time = tv.tv_sec;
80     local_tm = gmtime(&local_time);
81
82     systime->wYear = local_tm->tm_year + 1900;
83     systime->wMonth = local_tm->tm_mon + 1;
84     systime->wDayOfWeek = local_tm->tm_wday;
85     systime->wDay = local_tm->tm_mday;
86     systime->wHour = local_tm->tm_hour;
87     systime->wMinute = local_tm->tm_min;
88     systime->wSecond = local_tm->tm_sec;
89     systime->wMilliseconds = (tv.tv_usec / 1000) % 1000;
90 }
91
92
93 /***********************************************************************
94  *              SetSystemTime            (KERNEL32.507)
95  */
96 BOOL WINAPI SetSystemTime(const SYSTEMTIME *systime)
97 {
98     struct timeval tv;
99     struct timezone tz;
100     struct tm t;
101     time_t sec;
102
103     /* call gettimeofday to get the current timezone */
104     gettimeofday(&tv, &tz);
105
106     /* get the number of seconds */
107     t.tm_sec = systime->wSecond;
108     t.tm_min = systime->wMinute;
109     t.tm_hour = systime->wHour;
110     t.tm_mday = systime->wDay;
111     t.tm_mon = systime->wMonth;
112     t.tm_year = systime->wYear;
113     sec = mktime (&t);
114
115     /* set the new time */
116     tv.tv_sec = sec;
117     tv.tv_usec = systime->wMilliseconds * 1000;
118     return !settimeofday(&tv, &tz);
119 }
120
121
122 /***********************************************************************
123  *              GetTimeZoneInformation  (KERNEL32.302)
124  */
125 DWORD WINAPI GetTimeZoneInformation(LPTIME_ZONE_INFORMATION tzinfo)
126 {
127     time_t gmt, lt;
128     struct tm *ptm;
129     int daylight;
130
131     memset(tzinfo, 0, sizeof(TIME_ZONE_INFORMATION));
132
133     gmt = time(NULL);
134     ptm=localtime(&gmt);
135     daylight=ptm->tm_isdst;
136
137     ptm = gmtime(&gmt);
138     ptm->tm_isdst=daylight;
139     lt = mktime(ptm);
140     
141     tzinfo->Bias = (lt - gmt) / 60;
142     tzinfo->StandardBias = 0;
143     tzinfo->DaylightBias = -60;
144
145     return TIME_ZONE_ID_UNKNOWN;
146 }
147
148
149 /***********************************************************************
150  *              SetTimeZoneInformation  (KERNEL32.515)
151  */
152 BOOL WINAPI SetTimeZoneInformation(const LPTIME_ZONE_INFORMATION tzinfo)
153 {
154     struct timezone tz;
155
156     tz.tz_minuteswest = tzinfo->Bias;
157 #ifdef DST_NONE
158     tz.tz_dsttime = DST_NONE;
159 #else
160     tz.tz_dsttime = 0;
161 #endif
162     return !settimeofday(NULL, &tz);
163 }
164
165
166 /***********************************************************************
167  *              GetSystemTimeAsFileTime  (KERNEL32)
168  */
169 VOID WINAPI GetSystemTimeAsFileTime(LPFILETIME systemtimeAsfiletime)
170 {
171     struct timeval now;
172     gettimeofday( &now, 0 );
173     /* FIXME: convert to UTC */
174     DOSFS_UnixTimeToFileTime( now.tv_sec, systemtimeAsfiletime, now.tv_usec * 10 );
175 }
176
177 /***********************************************************************
178  *              SystemTimeToTzSpecificLocalTime32  (KERNEL32.683)
179  */
180 BOOL WINAPI SystemTimeToTzSpecificLocalTime(
181   LPTIME_ZONE_INFORMATION lpTimeZoneInformation,
182   LPSYSTEMTIME lpUniversalTime,
183   LPSYSTEMTIME lpLocalTime) {
184
185   FIXME(":stub\n"); 
186   SetLastError(ERROR_CALL_NOT_IMPLEMENTED); 
187        return FALSE;
188 }