summaryrefslogtreecommitdiff
path: root/bsp/gkipc/libraries/drv/gnu_c/mkgmtime.c
blob: 0197f610e785291d95d6ad8a5609a8ad8a4cd492 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
/*
********************************************************************************
**
** \file        ./boot/startup/src/mktime.c
**
** \version     $Id: mkgmtime.c 6392 2016-03-21 09:20:06Z liuwei $
**
** \brief       ARM1176 RealView libc function retargeting.
**
** This files implements the time-specific extension function mkgmtime().
**
** \attention   THIS SAMPLE CODE IS PROVIDED AS IS. FUJITSU MICROELECTRONICS
**              ACCEPTS NO RESPONSIBILITY OR LIABILITY FOR ANY ERRORS OR
**              OMMISSIONS.
**
** (C) Copyright 2006-2010 by Fujitsu Microelectronics Europe GmbH
** (C) Copyright 2010 by Fujitsu Semiconductor Europe GmbH
**
********************************************************************************
**
** \note The following LINT statements have been suppressed:
**
** - Warning 586: function 'mktime' is deprecated. [MISRA 2004 Rule 20.12]
**
*****************************************************************************
*/

//**************************************************************************
//**************************************************************************
//** Standard includes
//**************************************************************************
//**************************************************************************

#include <string.h>
#include <time.h>
#include <internal.h>

//**************************************************************************
//**************************************************************************
//** FAPI includes
//**************************************************************************
//**************************************************************************

//#include <fapi/sys_services.h>

//**************************************************************************
//**************************************************************************
//** Defines and Macros
//**************************************************************************
//**************************************************************************

#define TZ_DEFAULT_DST_OFFSET    -3600    // in seconds (see same value in tzset)

//**************************************************************************
//**************************************************************************
//** Global Data
//**************************************************************************
//**************************************************************************

//******************************************************************************
//******************************************************************************
//** Local Functions Declaration
//******************************************************************************
//******************************************************************************

//******************************************************************************
//******************************************************************************
//** API Functions
//******************************************************************************
//******************************************************************************

/*
********************************************************************************
** \brief Implementation of the stdc library extension function.
**
** This is the standard C library extension function mkgmtime() from time_ext.h.
**
** The mkgmtime() function shall convert the broken-down time structure
** representing local time to the seconds since the Epoch expressed as
** coordinated universal time (UTC).
**
** \param tm Pointer to the broken-down time structure representing local time.
**
** \return The mkgmtime() function shall return the specified time since the
** Epoch encoded as a value of type time_t, where this value represents the time
** based on UTC. If the time since the Epoch cannot be represented, the function
** shall return the value (time_t)-1.
********************************************************************************
*/
time_t mkgmtime(struct tm *tm)
{
    time_t t;

    /* check parameter validity */
    if (tm == NULL) {
        return (time_t) (-1);
    }

    /* retrieve seconds since epoch of given local time and normalize data */
    t = /*lint -e(586) */ mktime(tm);

    /* apply time tone shift */
    t += (time_t) _timezone;

    /* check, which TZ offset (std or dst) should be applied and return */
    if ((*tzname[1] != '\0') && (tm->tm_isdst > 0)) {
        t += (time_t) _daylight;
    }

    return (time_t) (t);
}