ReactOS 0.4.15-dev-7934-g1dc8d80
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 */
19localtime_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
46extern char _tz_is_set;
48struct tm *
49localtime(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
#define EINVAL
Definition: acclib.h:90
#define _CRT_WIDE(_String)
Definition: crtdefs.h:55
int errno_t
Definition: crtdefs.h:374
#define NULL
Definition: types.h:112
__kernel_time_t time_t
Definition: linux.h:252
#define _MAX__TIME64_T
Definition: localtime.c:14
errno_t localtime_s(struct tm *_tm, const time_t *ptime)
Definition: localtime.c:17
struct tm * localtime(const time_t *ptime)
Definition: localtime.c:47
char _tz_is_set
Definition: timezone.c:10
__u16 time
Definition: mkdosfs.c:8
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
errno_t __cdecl _set_errno(_In_ int _Value)
_CRTIMP struct tm *__cdecl gmtime(const time_t *_Time)
Definition: time.h:415
_CRTIMP void __cdecl _tzset(void)
Definition: timezone.c:92
long _dstbias
Definition: timezone.c:62
long _timezone
Definition: timezone.c:46
#define memset(x, y, z)
Definition: compat.h:39
Definition: time.h:68
int tm_isdst
Definition: time.h:77