Kai Tietz | fb238a7 | 2012-08-07 11:17:20 +0000 | [diff] [blame] | 1 | #include <windows.h> |
| 2 | #include <malloc.h> |
| 3 | #include <time.h> |
| 4 | #include <errno.h> |
Jacek Caban | a5c387c | 2013-06-17 13:12:21 +0000 | [diff] [blame] | 5 | #include <msvcrt.h> |
Kai Tietz | fb238a7 | 2012-08-07 11:17:20 +0000 | [diff] [blame] | 6 | |
Kai Tietz | fb238a7 | 2012-08-07 11:17:20 +0000 | [diff] [blame] | 7 | /* struct tm * __cdecl _gmtime64 (const __time64_t *); */ |
| 8 | errno_t __cdecl _gmtime64_s (struct tm *, const __time64_t *); |
| 9 | static errno_t __cdecl _int_gmtime64_s (struct tm *, const __time64_t *); |
| 10 | static errno_t __cdecl _stub (struct tm *, const __time64_t *); |
| 11 | |
| 12 | errno_t __cdecl (*__MINGW_IMP_SYMBOL(_gmtime64_s))(struct tm *, const __time64_t *) = |
| 13 | _stub; |
| 14 | |
| 15 | static 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 | |
| 31 | errno_t __cdecl |
| 32 | _gmtime64_s (struct tm *ptm, const __time64_t *pt) |
| 33 | { |
| 34 | return _stub (ptm, pt); |
| 35 | } |
| 36 | |
| 37 | static errno_t __cdecl |
| 38 | _int_gmtime64_s (struct tm *ptm, const __time64_t *pt) |
| 39 | { |
| 40 | struct tm *ltm; |
Kai Tietz | fb238a7 | 2012-08-07 11:17:20 +0000 | [diff] [blame] | 41 | |
| 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 | } |