• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #include <windows.h>
2 #include <malloc.h>
3 #include <time.h>
4 #include <errno.h>
5 #include <msvcrt.h>
6 
7 static errno_t __cdecl _int_wctime64_s (wchar_t *, size_t, const __time64_t *);
8 static errno_t __cdecl _stub (wchar_t *, size_t, const __time64_t *);
9 
10 errno_t __cdecl (*__MINGW_IMP_SYMBOL(_wctime64_s))(wchar_t *, size_t, const __time64_t *) =
11  _stub;
12 
13 static errno_t __cdecl
_stub(wchar_t * d,size_t dn,const __time64_t * pt)14 _stub (wchar_t *d, size_t dn, const __time64_t *pt)
15 {
16   errno_t __cdecl (*f)(wchar_t*,size_t, const __time64_t *) = __MINGW_IMP_SYMBOL(_wctime64_s);
17 
18   if (f == _stub)
19     {
20 	f = (errno_t __cdecl (*)(wchar_t *, size_t, const __time64_t *))
21 	    GetProcAddress (__mingw_get_msvcrt_handle (), "_wctime64_s");
22 	if (!f)
23 	  f = _int_wctime64_s;
24 	__MINGW_IMP_SYMBOL(_wctime64_s) = f;
25     }
26   return (*f)(d, dn, pt);
27 }
28 
29 errno_t __cdecl
_wctime64_s(wchar_t * d,size_t dn,const __time64_t * pt)30 _wctime64_s (wchar_t *d, size_t dn, const __time64_t *pt)
31 {
32   return _stub (d, dn, pt);
33 }
34 
35 static errno_t __cdecl
_int_wctime64_s(wchar_t * d,size_t dn,const __time64_t * pt)36 _int_wctime64_s (wchar_t *d, size_t dn, const __time64_t *pt)
37 {
38   struct tm ltm;
39   errno_t e;
40 
41   if (!d || !dn)
42      {
43         errno = EINVAL;
44 	return EINVAL;
45      }
46   d[0] = 0;
47   if (!pt)
48      {
49 	errno = EINVAL;
50 	return EINVAL;
51      }
52 
53   if ((e = _localtime64_s (&ltm, pt)) != 0)
54     return e;
55   return _wasctime_s (d, dn, &ltm);
56 }
57