ReactOS  0.4.14-dev-315-gbb6fece
localtime.c
Go to the documentation of this file.
1 /*
2  * COPYRIGHT: LGPL, See LGPL.txt in the top level directory
3  * PROJECT: ReactOS CRT library
4  * FILE: lib/sdk/crt/time/localtime.c
5  * PURPOSE: Implementation of localtime, localtime_s
6  * PROGRAMERS: Timo Kreuzer
7  * Samuel Serapión
8  */
9 #include <precomp.h>
10 #include <time.h>
11 #include "bitsfixup.h"
12 
13 //fix me: header?
14 #define _MAX__TIME64_T 0x793406fffLL /* number of seconds from
15  00:00:00, 01/01/1970 UTC to
16  23:59:59. 12/31/3000 UTC */
17 
18 errno_t
19 localtime_s(struct tm* _tm, const time_t *ptime)
20 {
21  /* check for NULL */
22  if (!_tm || !ptime )
23  {
24  if(_tm) memset(_tm, 0xFF, sizeof(struct tm));
26  0,//__FUNCTION__,
27  _CRT_WIDE(__FILE__),
28  __LINE__,
29  0);
31  return EINVAL;
32  }
33 
34  /* Validate input */
35  if (*ptime < 0 || *ptime > _MAX__TIME64_T)
36  {
37  memset(_tm, 0xFF, sizeof(struct tm));
39  return EINVAL;
40  }
41 
42  _tm = localtime(ptime);
43  return 0;
44 }
45 
46 extern char _tz_is_set;
47 
48 struct tm *
49 localtime(const time_t *ptime)
50 {
51  time_t time = *ptime;
52  struct tm * ptm;
53 
54  /* Check for invalid time value */
55  if (time < 0)
56  {
57  return 0;
58  }
59 
60  /* Never without */
61  if (!_tz_is_set)
62  _tzset();
63 
64  /* Check for overflow */
65 
66  /* Correct for timezone */
67  time -= _timezone;
68 #if 0
69  /* Correct for daylight saving */
70  if (_isdstime(time))
71  {
72  ptm->tm_isdst = 1;
73  time -= _dstbias;
74  }
75 #endif
76  ptm = gmtime(&time);
77 
78  return ptm;
79 }
80 
errno_t __cdecl _set_errno(_In_ int _Value)
errno_t localtime_s(struct tm *_tm, const time_t *ptime)
Definition: localtime.c:19
_CRTIMP void __cdecl _tzset(void)
Definition: timezone.c:92
Definition: arc.h:39
__u16 time
Definition: mkdosfs.c:366
char _tz_is_set
Definition: timezone.c:10
smooth NULL
Definition: ftsmooth.c:416
int errno_t
Definition: crtdefs.h:353
long _dstbias
Definition: timezone.c:62
Definition: time.h:76
#define _MAX__TIME64_T
Definition: localtime.c:14
long _timezone
Definition: timezone.c:46
__kernel_time_t time_t
Definition: linux.h:252
struct tm * localtime(const time_t *ptime)
Definition: localtime.c:49
_CRTIMP struct tm *__cdecl gmtime(const time_t *_Time)
Definition: time.h:423
#define _CRT_WIDE(_String)
Definition: crtdefs.h:43
int tm_isdst
Definition: time.h:85
#define memset(x, y, z)
Definition: compat.h:39
void _invalid_parameter(const wchar_t *expression, const wchar_t *function, const wchar_t *file, unsigned int line, uintptr_t pReserved)
Definition: errno.c:137