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