C Run-Time Libraries (CRT) Time Management Routines Wrapper Implementation\r
for OpenSSL-based Cryptographic Library (used in DXE & RUNTIME).\r
\r
-Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>\r
This program and the accompanying materials\r
are licensed and made available under the terms and conditions of the BSD License\r
which accompanies this distribution. The full text of the license may be found at\r
//\r
\r
#define IsLeap(y) (((y) % 4) == 0 && (((y) % 100) != 0 || ((y) % 400) == 0))\r
+#define SECSPERMIN (60)\r
#define SECSPERHOUR (60 * 60)\r
#define SECSPERDAY (24 * SECSPERHOUR)\r
\r
\r
return *timer;\r
}\r
+\r
+//\r
+// Convert a time value from type time_t to struct tm.\r
+//\r
+struct tm * gmtime (const time_t *timer)\r
+{\r
+ struct tm *GmTime;\r
+ UINT16 DayNo;\r
+ UINT16 DayRemainder;\r
+ time_t Year;\r
+ time_t YearNo;\r
+ UINT16 TotalDays;\r
+ UINT16 MonthNo;\r
+\r
+ if (timer == NULL) {\r
+ return NULL;\r
+ }\r
+\r
+ GmTime = malloc (sizeof (struct tm));\r
+ if (GmTime == NULL) {\r
+ return NULL;\r
+ }\r
+\r
+ ZeroMem ((VOID *) GmTime, (UINTN) sizeof (struct tm));\r
+\r
+ DayNo = (UINT16) (*timer / SECSPERDAY);\r
+ DayRemainder = (UINT16) (*timer % SECSPERDAY);\r
+\r
+ GmTime->tm_sec = (int) (DayRemainder % SECSPERMIN);\r
+ GmTime->tm_min = (int) ((DayRemainder % SECSPERHOUR) / SECSPERMIN);\r
+ GmTime->tm_hour = (int) (DayRemainder / SECSPERHOUR);\r
+ GmTime->tm_wday = (int) ((DayNo + 4) % 7);\r
+\r
+ for (Year = 1970, YearNo = 0; DayNo > 0; Year++) {\r
+ TotalDays = (UINT16) (IsLeap (Year) ? 366 : 365);\r
+ if (DayNo >= TotalDays) {\r
+ DayNo = (UINT16) (DayNo - TotalDays);\r
+ YearNo++;\r
+ } else {\r
+ break;\r
+ }\r
+ }\r
+\r
+ GmTime->tm_year = (int) (YearNo + (1970 - 1900));\r
+ GmTime->tm_yday = (int) DayNo;\r
+\r
+ for (MonthNo = 12; MonthNo > 1; MonthNo--) {\r
+ if (DayNo > CumulativeDays[IsLeap(Year)][MonthNo]) {\r
+ DayNo = (UINT16) (DayNo - (UINT16) (CumulativeDays[IsLeap(Year)][MonthNo]));\r
+ break;\r
+ }\r
+ }\r
+\r
+ GmTime->tm_mon = (int) MonthNo;\r
+ GmTime->tm_mday = (int) DayNo;\r
+\r
+ GmTime->tm_isdst = 0;\r
+ GmTime->tm_gmtoff = 0;\r
+ GmTime->tm_zone = NULL;\r
+\r
+ return GmTime;\r
+}\r