blob: e9d708388f43ec965bad5d7d66bc595ffc6d58ea [file] [log] [blame]
Kai Tietzfb238a72012-08-07 11:17:20 +00001#include <windows.h>
2#include <malloc.h>
3#include <time.h>
4#include <errno.h>
Jacek Cabana5c387c2013-06-17 13:12:21 +00005#include <msvcrt.h>
Kai Tietzfb238a72012-08-07 11:17:20 +00006
Kai Tietzfb238a72012-08-07 11:17:20 +00007/* struct tm * __cdecl _gmtime64 (const __time64_t *); */
8errno_t __cdecl _gmtime64_s (struct tm *, const __time64_t *);
9static errno_t __cdecl _int_gmtime64_s (struct tm *, const __time64_t *);
10static errno_t __cdecl _stub (struct tm *, const __time64_t *);
11
12errno_t __cdecl (*__MINGW_IMP_SYMBOL(_gmtime64_s))(struct tm *, const __time64_t *) =
13 _stub;
14
15static errno_t __cdecl
16_stub (struct tm *ptm, const __time64_t *pt)
17{
18 errno_t __cdecl (*f)(struct tm *, const __time64_t *) = __MINGW_IMP_SYMBOL(_gmtime64_s);
19
20 if (f == _stub)
21 {
22 f = (errno_t __cdecl (*)(struct tm *, const __time64_t *))
23 GetProcAddress (__mingw_get_msvcrt_handle (), "_gmtime64_s");
24 if (!f)
25 f = _int_gmtime64_s;
26 __MINGW_IMP_SYMBOL(_gmtime64_s) = f;
27 }
28 return (*f)(ptm, pt);
29}
30
31errno_t __cdecl
32_gmtime64_s (struct tm *ptm, const __time64_t *pt)
33{
34 return _stub (ptm, pt);
35}
36
37static errno_t __cdecl
38_int_gmtime64_s (struct tm *ptm, const __time64_t *pt)
39{
40 struct tm *ltm;
Kai Tietzfb238a72012-08-07 11:17:20 +000041
42 if (ptm)
43 memset (ptm, 0xff, sizeof (*ptm));
44 if (!ptm || !pt)
45 {
46 errno = EINVAL;
47 return EINVAL;
48 }
49 if ((ltm = _gmtime64 (pt)) == NULL)
50 return errno;
51 *ptm = *ltm;
52 return 0;
53}