blob: 0dadd96a3030ef8567f7af9718d02efa984be1ff [file] [log] [blame]
Kai Tietzd0345db2012-08-07 08:45:00 +00001#include <windows.h>
2#include <malloc.h>
3#include <time.h>
4#include <errno.h>
5
6HMODULE __mingw_get_msvcrt_handle (void);
7errno_t __cdecl _localtime64_s (struct tm *, const __time64_t *);
8errno_t __cdecl asctime_s (char *, size_t, const struct tm *);
9errno_t __cdecl _ctime64_s (char *, size_t, const __time64_t *);
10static errno_t __cdecl _int_ctime64_s (char *, size_t, const __time64_t *);
11static errno_t __cdecl _stub (char *, size_t, const __time64_t *);
12
13errno_t __cdecl (*__MINGW_IMP_SYMBOL(_ctime64_s))(char *, size_t, const __time64_t *) =
14 _stub;
15
16static errno_t __cdecl
17_stub (char *d, size_t dn, const __time64_t *pt)
18{
19 errno_t __cdecl (*f)(char *, size_t, const __time64_t *) = __MINGW_IMP_SYMBOL(_ctime64_s);
20
21 if (f == _stub)
22 {
23 f = (errno_t __cdecl (*)(char *, size_t, const __time64_t *))
24 GetProcAddress (__mingw_get_msvcrt_handle (), "_ctime64_s");
25 if (!f)
26 f = _int_ctime64_s;
27 __MINGW_IMP_SYMBOL(_ctime64_s) = f;
28 }
29 return (*f)(d, dn, pt);
30}
31
32errno_t __cdecl
33_ctime64_s (char *d, size_t dn, const __time64_t *pt)
34{
35 return _stub (d, dn, pt);
36}
37
38static errno_t __cdecl
39_int_ctime64_s (char *d, size_t dn, const __time64_t *pt)
40{
41 struct tm ltm;
42 errno_t e;
43
44 if (!d || !dn)
45 {
46 errno = EINVAL;
47 return EINVAL;
48 }
49 d[0] = 0;
50 if (!pt)
51 {
52 errno = EINVAL;
53 return EINVAL;
54 }
55
56 if ((e = _localtime64_s (&ltm, pt)) != 0)
57 return e;
58 return asctime_s (d, dn, &ltm);
59}