mkgmtime.c 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*
  2. ********************************************************************************
  3. **
  4. ** \file ./boot/startup/src/mktime.c
  5. **
  6. ** \version $Id: mkgmtime.c 6392 2016-03-21 09:20:06Z liuwei $
  7. **
  8. ** \brief ARM1176 RealView libc function retargeting.
  9. **
  10. ** This files implements the time-specific extension function mkgmtime().
  11. **
  12. ** \attention THIS SAMPLE CODE IS PROVIDED AS IS. FUJITSU MICROELECTRONICS
  13. ** ACCEPTS NO RESPONSIBILITY OR LIABILITY FOR ANY ERRORS OR
  14. ** OMMISSIONS.
  15. **
  16. ** (C) Copyright 2006-2010 by Fujitsu Microelectronics Europe GmbH
  17. ** (C) Copyright 2010 by Fujitsu Semiconductor Europe GmbH
  18. **
  19. ********************************************************************************
  20. **
  21. ** \note The following LINT statements have been suppressed:
  22. **
  23. ** - Warning 586: function 'mktime' is deprecated. [MISRA 2004 Rule 20.12]
  24. **
  25. *****************************************************************************
  26. */
  27. //**************************************************************************
  28. //**************************************************************************
  29. //** Standard includes
  30. //**************************************************************************
  31. //**************************************************************************
  32. #include <string.h>
  33. #include <time.h>
  34. #include <internal.h>
  35. //**************************************************************************
  36. //**************************************************************************
  37. //** FAPI includes
  38. //**************************************************************************
  39. //**************************************************************************
  40. //#include <fapi/sys_services.h>
  41. //**************************************************************************
  42. //**************************************************************************
  43. //** Defines and Macros
  44. //**************************************************************************
  45. //**************************************************************************
  46. #define TZ_DEFAULT_DST_OFFSET -3600 // in seconds (see same value in tzset)
  47. //**************************************************************************
  48. //**************************************************************************
  49. //** Global Data
  50. //**************************************************************************
  51. //**************************************************************************
  52. //******************************************************************************
  53. //******************************************************************************
  54. //** Local Functions Declaration
  55. //******************************************************************************
  56. //******************************************************************************
  57. //******************************************************************************
  58. //******************************************************************************
  59. //** API Functions
  60. //******************************************************************************
  61. //******************************************************************************
  62. /*
  63. ********************************************************************************
  64. ** \brief Implementation of the stdc library extension function.
  65. **
  66. ** This is the standard C library extension function mkgmtime() from time_ext.h.
  67. **
  68. ** The mkgmtime() function shall convert the broken-down time structure
  69. ** representing local time to the seconds since the Epoch expressed as
  70. ** coordinated universal time (UTC).
  71. **
  72. ** \param tm Pointer to the broken-down time structure representing local time.
  73. **
  74. ** \return The mkgmtime() function shall return the specified time since the
  75. ** Epoch encoded as a value of type time_t, where this value represents the time
  76. ** based on UTC. If the time since the Epoch cannot be represented, the function
  77. ** shall return the value (time_t)-1.
  78. ********************************************************************************
  79. */
  80. time_t mkgmtime(struct tm *tm)
  81. {
  82. time_t t;
  83. /* check parameter validity */
  84. if (tm == NULL) {
  85. return (time_t) (-1);
  86. }
  87. /* retrieve seconds since epoch of given local time and normalize data */
  88. t = /*lint -e(586) */ mktime(tm);
  89. /* apply time tone shift */
  90. t += (time_t) _timezone;
  91. /* check, which TZ offset (std or dst) should be applied and return */
  92. if ((*tzname[1] != '\0') && (tm->tm_isdst > 0)) {
  93. t += (time_t) _daylight;
  94. }
  95. return (time_t) (t);
  96. }