summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGerd Hoffmann <kraxel@redhat.com>2024-06-11 11:53:24 +0200
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>2024-09-25 16:08:35 +0000
commitaf73d37741efa54044a795e22dda48f612547874 (patch)
tree45a3d46305a640153584fd1f01b211d06369f3e0
parentebf7daa583f742129765c62cbd99de58e3300dd8 (diff)
downloadedk2-af73d37741efa54044a795e22dda48f612547874.tar.gz
CrtLibSupport: factor out EFI_TIME -> time_t calculation to new function
No functional change. Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
-rw-r--r--CryptoPkg/Library/BaseCryptLib/SysCall/TimerWrapper.c51
1 files changed, 32 insertions, 19 deletions
diff --git a/CryptoPkg/Library/BaseCryptLib/SysCall/TimerWrapper.c b/CryptoPkg/Library/BaseCryptLib/SysCall/TimerWrapper.c
index ff3278caea..2e83041cf8 100644
--- a/CryptoPkg/Library/BaseCryptLib/SysCall/TimerWrapper.c
+++ b/CryptoPkg/Library/BaseCryptLib/SysCall/TimerWrapper.c
@@ -80,6 +80,37 @@ IsLeap (
return (Remainder1 == 0 && (Remainder2 != 0 || Remainder3 == 0));
}
+STATIC
+time_t
+CalculateTimeT (
+ EFI_TIME *Time
+ )
+{
+ time_t CalTime;
+ UINTN Year;
+
+ //
+ // Years Handling
+ // UTime should now be set to 00:00:00 on Jan 1 of the current year.
+ //
+ for (Year = 1970, CalTime = 0; Year != Time->Year; Year++) {
+ CalTime = CalTime + (time_t)(CumulativeDays[IsLeap (Year)][13] * SECSPERDAY);
+ }
+
+ //
+ // Add in number of seconds for current Month, Day, Hour, Minute, Seconds, and TimeZone adjustment
+ //
+ CalTime = CalTime +
+ (time_t)((Time->TimeZone != EFI_UNSPECIFIED_TIMEZONE) ? (Time->TimeZone * 60) : 0) +
+ (time_t)(CumulativeDays[IsLeap (Time->Year)][Time->Month] * SECSPERDAY) +
+ (time_t)(((Time->Day > 0) ? Time->Day - 1 : 0) * SECSPERDAY) +
+ (time_t)(Time->Hour * SECSPERHOUR) +
+ (time_t)(Time->Minute * 60) +
+ (time_t)Time->Second;
+
+ return CalTime;
+}
+
/* Get the system time as seconds elapsed since midnight, January 1, 1970. */
// INTN time(
// INTN *timer
@@ -92,7 +123,6 @@ time (
EFI_STATUS Status;
EFI_TIME Time;
time_t CalTime;
- UINTN Year;
//
// Get the current time and date information
@@ -102,24 +132,7 @@ time (
return 0;
}
- //
- // Years Handling
- // UTime should now be set to 00:00:00 on Jan 1 of the current year.
- //
- for (Year = 1970, CalTime = 0; Year != Time.Year; Year++) {
- CalTime = CalTime + (time_t)(CumulativeDays[IsLeap (Year)][13] * SECSPERDAY);
- }
-
- //
- // Add in number of seconds for current Month, Day, Hour, Minute, Seconds, and TimeZone adjustment
- //
- CalTime = CalTime +
- (time_t)((Time.TimeZone != EFI_UNSPECIFIED_TIMEZONE) ? (Time.TimeZone * 60) : 0) +
- (time_t)(CumulativeDays[IsLeap (Time.Year)][Time.Month] * SECSPERDAY) +
- (time_t)(((Time.Day > 0) ? Time.Day - 1 : 0) * SECSPERDAY) +
- (time_t)(Time.Hour * SECSPERHOUR) +
- (time_t)(Time.Minute * 60) +
- (time_t)Time.Second;
+ CalTime = CalculateTimeT (&Time);
if (timer != NULL) {
*timer = CalTime;