Fixed some issues found by winapi_check.
[wine] / win32 / time.c
1 /*
2  * Win32 kernel functions
3  *
4  * Copyright 1995 Martin von Loewis and Cameron Heide
5  *
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.
10  *
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.
15  *
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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20
21 #include "config.h"
22 #include "wine/port.h"
23
24 #include <string.h>
25 #include <time.h>
26 #ifdef HAVE_SYS_TIME_H
27 # include <sys/time.h>
28 #endif
29 #ifdef HAVE_UNISTD_H
30 # include <unistd.h>
31 #endif
32 #include "file.h"
33 #include "winerror.h"
34 #include "wine/debug.h"
35
36 WINE_DEFAULT_DEBUG_CHANNEL(win32);
37
38 /***********************************************************************
39  *              GetLocalTime            (KERNEL32.@)
40  */
41 VOID WINAPI GetLocalTime(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 = localtime(&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  *              GetSystemTime            (KERNEL32.@)
63  */
64 VOID WINAPI GetSystemTime(LPSYSTEMTIME systime)
65 {
66     time_t system_time;
67     struct tm *system_tm;
68     struct timeval tv;
69
70     gettimeofday(&tv, NULL);
71     system_time = tv.tv_sec;
72     system_tm = gmtime(&system_time);
73
74     systime->wYear = system_tm->tm_year + 1900;
75     systime->wMonth = system_tm->tm_mon + 1;
76     systime->wDayOfWeek = system_tm->tm_wday;
77     systime->wDay = system_tm->tm_mday;
78     systime->wHour = system_tm->tm_hour;
79     systime->wMinute = system_tm->tm_min;
80     systime->wSecond = system_tm->tm_sec;
81     systime->wMilliseconds = (tv.tv_usec / 1000) % 1000;
82 }