Removed a lot of occurences of windows.h (and added necessary other
[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 "debug.h"
14
15 /***********************************************************************
16  *              GetLocalTime            (KERNEL32.228)
17  */
18 VOID WINAPI GetLocalTime(LPSYSTEMTIME systime)
19 {
20     time_t local_time;
21     struct tm *local_tm;
22     struct timeval tv;
23
24     gettimeofday(&tv, NULL);
25     local_time = tv.tv_sec;
26     local_tm = localtime(&local_time);
27
28     systime->wYear = local_tm->tm_year + 1900;
29     systime->wMonth = local_tm->tm_mon + 1;
30     systime->wDayOfWeek = local_tm->tm_wday;
31     systime->wDay = local_tm->tm_mday;
32     systime->wHour = local_tm->tm_hour;
33     systime->wMinute = local_tm->tm_min;
34     systime->wSecond = local_tm->tm_sec;
35     systime->wMilliseconds = (tv.tv_usec / 1000) % 1000;
36 }
37
38 /***********************************************************************
39  *              GetSystemTime            (KERNEL32.285)
40  */
41 VOID WINAPI GetSystemTime(LPSYSTEMTIME systime)
42 {
43     time_t local_time;
44     struct tm *local_tm;
45     struct timeval tv;
46
47     gettimeofday(&tv, NULL);
48     local_time = tv.tv_sec;
49     local_tm = gmtime(&local_time);
50
51     systime->wYear = local_tm->tm_year + 1900;
52     systime->wMonth = local_tm->tm_mon + 1;
53     systime->wDayOfWeek = local_tm->tm_wday;
54     systime->wDay = local_tm->tm_mday;
55     systime->wHour = local_tm->tm_hour;
56     systime->wMinute = local_tm->tm_min;
57     systime->wSecond = local_tm->tm_sec;
58     systime->wMilliseconds = (tv.tv_usec / 1000) % 1000;
59 }
60
61
62 /***********************************************************************
63  *              SetSystemTime            (KERNEL32.507)
64  */
65 BOOL32 WINAPI SetSystemTime(const SYSTEMTIME *systime)
66 {
67     struct timeval tv;
68     struct timezone tz;
69     struct tm t;
70     time_t sec;
71
72     /* call gettimeofday to get the current timezone */
73     gettimeofday(&tv, &tz);
74
75     /* get the number of seconds */
76     t.tm_sec = systime->wSecond;
77     t.tm_min = systime->wMinute;
78     t.tm_hour = systime->wHour;
79     t.tm_mday = systime->wDay;
80     t.tm_mon = systime->wMonth;
81     t.tm_year = systime->wYear;
82     sec = mktime (&t);
83
84     /* set the new time */
85     tv.tv_sec = sec;
86     tv.tv_usec = systime->wMilliseconds * 1000;
87     if (settimeofday(&tv, &tz))
88     {
89         return FALSE;
90     }
91     else
92     {
93         return TRUE;
94     }
95 }
96
97
98 /***********************************************************************
99  *              GetTimeZoneInformation  (KERNEL32.302)
100  */
101 DWORD WINAPI GetTimeZoneInformation(LPTIME_ZONE_INFORMATION tzinfo)
102 {
103     time_t gmt, lt;
104
105     memset(tzinfo, 0, sizeof(TIME_ZONE_INFORMATION));
106
107     gmt = time(NULL);
108     lt = mktime(gmtime(&gmt));
109     tzinfo->Bias = (lt - gmt) / 60;
110     tzinfo->StandardBias = 0;
111     tzinfo->DaylightBias = -60;
112
113     return TIME_ZONE_ID_UNKNOWN;
114 }
115
116
117 /***********************************************************************
118  *              SetTimeZoneInformation  (KERNEL32.515)
119  */
120 BOOL32 WINAPI SetTimeZoneInformation(const LPTIME_ZONE_INFORMATION tzinfo)
121 {
122     struct timezone tz;
123
124     tz.tz_minuteswest = tzinfo->Bias;
125 #ifdef DST_NONE
126     tz.tz_dsttime = DST_NONE;
127 #else
128     tz.tz_dsttime = 0;
129 #endif
130     return !settimeofday(NULL, &tz);
131 }
132
133
134 /***********************************************************************
135  *              GetSystemTimeAsFileTime  (KERNEL32)
136  */
137 VOID WINAPI GetSystemTimeAsFileTime(LPFILETIME systemtimeAsfiletime) {
138         DOSFS_UnixTimeToFileTime(time(NULL),systemtimeAsfiletime,0);
139 }
140
141 /***********************************************************************
142  *              SystemTimeToTzSpecificLocalTime32  (KERNEL32.683)
143  */
144 BOOL32 WINAPI SystemTimeToTzSpecificLocalTime32(
145   LPTIME_ZONE_INFORMATION lpTimeZoneInformation,
146   LPSYSTEMTIME lpUniversalTime,
147   LPSYSTEMTIME lpLocalTime) {
148
149   FIXME(win32, ":stub\n"); 
150   SetLastError(ERROR_CALL_NOT_IMPLEMENTED); 
151        return FALSE;
152 }