]> git.proxmox.com Git - mirror_edk2.git/blame - CryptoPkg/Library/BaseCryptLib/SysCall/TimerWrapper.c
1. enable /GL optimization building on OpensslLib.
[mirror_edk2.git] / CryptoPkg / Library / BaseCryptLib / SysCall / TimerWrapper.c
CommitLineData
97f98500
HT
1/** @file\r
2 C Run-Time Libraries (CRT) Time Management Routines Wrapper Implementation\r
3 for OpenSSL-based Cryptographic Library (used in DXE & RUNTIME).\r
4\r
5Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
6This program and the accompanying materials\r
7are licensed and made available under the terms and conditions of the BSD License\r
8which accompanies this distribution. The full text of the license may be found at\r
9http://opensource.org/licenses/bsd-license.php\r
10\r
11THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13\r
14**/\r
15\r
16#include <Uefi.h>\r
17#include <OpenSslSupport.h>\r
18#include <Library/UefiRuntimeServicesTableLib.h>\r
19\r
20//\r
21// -- Time Management Routines --\r
22//\r
23\r
24#define IsLeap(y) (((y) % 4) == 0 && (((y) % 100) != 0 || ((y) % 400) == 0))\r
25#define SECSPERHOUR (60 * 60)\r
26#define SECSPERDAY (24 * SECSPERHOUR)\r
27\r
28//\r
29// The arrays give the cumulative number of days up to the first of the\r
30// month number used as the index (1 -> 12) for regular and leap years.\r
31// The value at index 13 is for the whole year.\r
32//\r
33UINTN CumulativeDays[2][14] = {\r
34 {\r
35 0,\r
36 0,\r
37 31,\r
38 31 + 28,\r
39 31 + 28 + 31,\r
40 31 + 28 + 31 + 30,\r
41 31 + 28 + 31 + 30 + 31,\r
42 31 + 28 + 31 + 30 + 31 + 30,\r
43 31 + 28 + 31 + 30 + 31 + 30 + 31,\r
44 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31,\r
45 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30,\r
46 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31,\r
47 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30,\r
48 31 + 28 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30 + 31\r
49 },\r
50 {\r
51 0,\r
52 0,\r
53 31,\r
54 31 + 29,\r
55 31 + 29 + 31,\r
56 31 + 29 + 31 + 30,\r
57 31 + 29 + 31 + 30 + 31,\r
58 31 + 29 + 31 + 30 + 31 + 30,\r
59 31 + 29 + 31 + 30 + 31 + 30 + 31,\r
60 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31,\r
61 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30,\r
62 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31,\r
63 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30,\r
64 31 + 29 + 31 + 30 + 31 + 30 + 31 + 31 + 30 + 31 + 30 + 31 \r
65 }\r
66};\r
67\r
68/* Get the system time as seconds elapsed since midnight, January 1, 1970. */\r
69//INTN time(\r
70// INTN *timer\r
71// )\r
72time_t time (time_t *timer)\r
73{\r
74 EFI_TIME Time;\r
75 UINTN Year;\r
76\r
77 //\r
78 // Get the current time and date information\r
79 //\r
80 gRT->GetTime (&Time, NULL);\r
81\r
82 //\r
83 // Years Handling\r
84 // UTime should now be set to 00:00:00 on Jan 1 of the current year.\r
85 //\r
86 for (Year = 1970, *timer = 0; Year != Time.Year; Year++) {\r
87 *timer = *timer + (time_t)(CumulativeDays[IsLeap(Year)][13] * SECSPERDAY);\r
88 }\r
89\r
90 //\r
91 // Add in number of seconds for current Month, Day, Hour, Minute, Seconds, and TimeZone adjustment\r
92 //\r
93 *timer = *timer + \r
94 (time_t)((Time.TimeZone != EFI_UNSPECIFIED_TIMEZONE) ? (Time.TimeZone * 60) : 0) +\r
95 (time_t)(CumulativeDays[IsLeap(Time.Year)][Time.Month] * SECSPERDAY) + \r
96 (time_t)(((Time.Day > 0) ? Time.Day - 1 : 0) * SECSPERDAY) + \r
97 (time_t)(Time.Hour * SECSPERHOUR) + \r
98 (time_t)(Time.Minute * 60) + \r
99 (time_t)Time.Second;\r
100\r
101 return *timer;\r
102}\r