Use snprintf to prevent buffer overflows in format_exception_msg.
[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.@)
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  *              GetSystemTime            (KERNEL32.@)
42  */
43 VOID WINAPI GetSystemTime(LPSYSTEMTIME systime)
44 {
45     time_t local_time;
46     struct tm *local_tm;
47     struct timeval tv;
48
49     gettimeofday(&tv, NULL);
50     local_time = tv.tv_sec;
51     local_tm = gmtime(&local_time);
52
53     systime->wYear = local_tm->tm_year + 1900;
54     systime->wMonth = local_tm->tm_mon + 1;
55     systime->wDayOfWeek = local_tm->tm_wday;
56     systime->wDay = local_tm->tm_mday;
57     systime->wHour = local_tm->tm_hour;
58     systime->wMinute = local_tm->tm_min;
59     systime->wSecond = local_tm->tm_sec;
60     systime->wMilliseconds = (tv.tv_usec / 1000) % 1000;
61 }