• 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_localtime32_s (struct tm *, const __time32_t *);
8 static errno_t __cdecl _stub (struct tm *, const __time32_t *);
9 
10 errno_t __cdecl (*__MINGW_IMP_SYMBOL(_localtime32_s))(struct tm *, const __time32_t *) =
11  _stub;
12 
13 static errno_t __cdecl
_stub(struct tm * ptm,const __time32_t * pt)14 _stub (struct tm *ptm, const __time32_t *pt)
15 {
16   errno_t __cdecl (*f)(struct tm *, const __time32_t *) = __MINGW_IMP_SYMBOL(_localtime32_s);
17 
18   if (f == _stub)
19     {
20 	f = (errno_t __cdecl (*)(struct tm *, const __time32_t *))
21 	    GetProcAddress (__mingw_get_msvcrt_handle (), "_localtime32_s");
22 	if (!f)
23 	  f = _int_localtime32_s;
24 	__MINGW_IMP_SYMBOL(_localtime32_s) = f;
25     }
26   return (*f)(ptm, pt);
27 }
28 
29 errno_t __cdecl
_localtime32_s(struct tm * ptm,const __time32_t * pt)30 _localtime32_s (struct tm *ptm, const __time32_t *pt)
31 {
32   return _stub (ptm, pt);
33 }
34 
35 static errno_t __cdecl
_int_localtime32_s(struct tm * ptm,const __time32_t * pt)36 _int_localtime32_s (struct tm *ptm, const __time32_t *pt)
37 {
38   struct tm *ltm;
39 
40   if (ptm)
41     memset (ptm, 0xff, sizeof (*ptm));
42   if (!ptm || !pt)
43      {
44         errno = EINVAL;
45 	return EINVAL;
46      }
47   if ((ltm = _localtime32 (pt)) == NULL)
48     return errno;
49   *ptm = *ltm;
50   return 0;
51 }
52