/**
Definitions and Implementation for <time.h>.
Copyright (c) 2010 - 2011, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials are licensed and made available under
the terms and conditions of the BSD License that accompanies this distribution.
The full text of the license may be found at
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Portions derived from the NIH time zone package file, localtime.c,
which contains the following notice:
This file is in the public domain, so clarified as of
1996-06-05 by Arthur David Olson (arthur_david_olson@nih.gov).
NetBSD: localtime.c,v 1.39 2006/03/22 14:01:30 christos Exp
**/
#include <Uefi.h>
#include <Library/TimerLib.h>
#include <Library/UefiRuntimeServicesTableLib.h>
//#include <Library/UefiRuntimeLib.h>
#include <LibConfig.h>
#include <errno.h>
#include <limits.h>
#include <time.h>
#include <reentrant.h>
#include "tzfile.h"
#include "TimeVals.h"
#include <MainData.h>
#if defined(_MSC_VER) /* Handle Microsoft VC++ compiler specifics. */
// Keep compiler quiet about casting from function to data pointers
#endif /* defined(_MSC_VER) */
/* ####################### Private Data ################################# */
#if 0
static EFI_TIME TimeBuffer;
00,
31, 59, 90, 120,
151, 181, 212, 243,
273, 304, 334
};
#endif
{ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
{ 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
};
};
"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
};
"Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
};
static int gmt_is_set;
/* ############### Implementation Functions ############################ */
// Forward reference
static void
__getCPS(void)
{
return gMD->ClocksPerSecond;
}
static void
const long offset,
)
{
time_t /*INTN*/ y;
int yleap;
const int * ip;
int hit;
int i;
corr = 0;
hit = 0;
#ifdef ALL_STATE
#endif /* defined ALL_STATE */
#ifndef ALL_STATE
#endif /* State Farm */
while (--i >= 0) {
if (hit)
while (i > 0 &&
{
++hit;
--i;
}
}
break;
}
}
while (rem < 0) {
rem += SECSPERDAY;
--days;
}
while (rem >= SECSPERDAY) {
rem -= SECSPERDAY;
++days;
}
/*
** A positive leap second requires a special
** representation. This uses "... ??:59:60" et seq.
*/
y = EPOCH_YEAR;
if (days < 0)
--newy;
LEAPS_THRU_END_OF(y - 1);
y = newy;
}
#ifdef TM_GMTOFF
#endif /* defined TM_GMTOFF */
}
/* ############### Time Manipulation Functions ########################## */
/**
**/
double
{
}
/*
** Adapted from code provided by Robert Elz, who writes:
** The "best" way to do mktime I think is based on an idea of Bob
** Kridle's (so its said...) from a long time ago.
** [kridle@xinet.com as of 1996-01-16.]
** It does a binary search of the time_t space. Since time_t's are
** just 32 bits, its a max of 32 iterations (even at 64 bits it
** would still be very reasonable).
*/
#ifndef WRONG
#endif /* !defined WRONG */
/*
** Simplified normalize logic courtesy Paul Eggert (eggert@twinsun.com).
*/
static int
{
int number0;
}
static int
{
register int tensdelta;
}
static int
{
register int result;
return result;
}
static time_t
const long offset,
int * const okayp,
const int do_norm_secs
)
{
register int dir;
register int bits;
register int i, j ;
register int saved_seconds;
time_t t;
if (do_norm_secs) {
return WRONG;
}
return WRONG;
return WRONG;
return WRONG;
/*
** Turn yourtm.tm_year into an actual year number for now.
** It is converted back to an offset from TM_YEAR_BASE later.
*/
return WRONG;
return WRONG;
}
return WRONG;
}
for ( ; ; ) {
break;
return WRONG;
}
}
return WRONG;
saved_seconds = 0;
/*
** We can't set tm_sec to 0, because that might push the
** time below the minimum representable time.
** Set tm_sec to 59 instead.
** This assumes that the minimum representable time is
** not in the same minute that a leap second was deleted from,
** which is a safer assumption than using 58 would be.
*/
return WRONG;
} else {
}
/*
** Divide the search space in half
** (this works whether time_t is signed or unsigned).
*/
/*
** Set t to the midpoint of our binary search.
**
** If time_t is signed, then 0 is just above the median,
** assuming two's complement arithmetic.
** If time_t is unsigned, then (1 << bits) is just above the median.
*/
for ( ; ; ) {
if (dir != 0) { // If mytm != yourtm...
if (bits-- < 0) // If we have exhausted all the bits..
return WRONG; // Return that we failed
if (bits < 0) // If on the last bit...
--t; /* may be needed if new t is minimal */
else if (dir > 0) // else if mytm > yourtm...
continue; // Repeat for the next half
}
break;
/*
** Right time, wrong type.
** Hunt for right time, right type.
** It's okay to guess wrong since the guess
** gets checked.
*/
/*
** The (void *) casts are the benefit of SunOS 3.3 on Sun 2's.
*/
#ifdef ALL_STATE
return WRONG;
#endif /* defined ALL_STATE */
continue;
continue;
continue;
continue;
/*
** We have a match.
*/
t = newt;
goto label;
}
}
return WRONG;
}
newt = t + saved_seconds;
if ((newt < t) != (saved_seconds < 0))
return WRONG;
t = newt;
return t;
}
{
time_t t;
/*
** First try without normalization of seconds
** (in case tm_sec contains a value associated with a leap second).
** If that fails, try with normalization of seconds.
*/
}
static time_t
const long offset
)
{
register time_t t;
register int i;
register int nseen;
int okay;
#ifdef PCTS
/*
** PCTS code courtesy Grant Sullivan (grant@osf.org).
*/
if (okay)
return t;
#endif /* defined PCTS */
#ifndef PCTS
return t;
#endif /* !defined PCTS */
/*
** We're supposed to assume that somebody took a time of one type
** and did some math on it that yielded a "struct tm" that's bad.
** We try to divine the type they started from and adjust to the
** type they need.
*/
/*
** The (void *) casts are the benefit of SunOS 3.3 on Sun 2's.
*/
#ifdef ALL_STATE
return WRONG;
#endif /* defined ALL_STATE */
nseen = 0;
}
continue;
continue;
if (okay)
return t;
}
}
return WRONG;
}
/** The mktime function converts the broken-down time, expressed as local time,
in the structure pointed to by timeptr into a calendar time value with the
same encoding as that of the values returned by the time function. The
original values of the tm_wday and tm_yday components of the structure are
ignored, and the original values of the other components are not restricted
to the ranges indicated above. Thus, a positive or zero value for tm_isdst
causes the mktime function to presume initially that Daylight Saving Time,
respectively, is or is not in effect for the specified time. A negative
value causes it to attempt to determine whether Daylight Saving Time is in
effect for the specified time. On successful completion, the values of the
tm_wday and tm_yday components of the structure are set appropriately, and
the other components are set to represent the specified calendar time, but
with their values forced to the ranges indicated above; the final value of
tm_mday is not set until tm_mon and tm_year are determined.
@return The mktime function returns the specified calendar time encoded
as a value of type time_t. If the calendar time cannot be
represented, the function returns the value (time_t)(-1).
**/
{
/* From NetBSD */
tzset();
return (result);
}
/** The time function determines the current calendar time. The encoding of
the value is unspecified.
@return The time function returns the implementation's best approximation
to the current calendar time. The value (time_t)(-1) is returned
if the calendar time is not available. If timer is not a null
pointer, the return value is also assigned to the object it
points to.
**/
{
// Get EFI Time
// Status = EfiGetTime( ET, NULL);
if( Status != RETURN_SUCCESS) {
return (time_t)-1;
}
// Convert EFI time to broken-down time.
// Convert to time_t
}
return CalTime; // Return calendar time in microseconds
}
/** The clock function determines the processor time used.
@return The clock function returns the implementation's best
approximation to the processor time used by the program since the
beginning of an implementation-defined era related only to the
program invocation. To determine the time in seconds, the value
returned by the clock function should be divided by the value of
the macro CLOCKS_PER_SEC. If the processor time used is not
available or its value cannot be represented, the function
returns the value (clock_t)(-1).
**/
clock(void)
{
return retval;
}
/* ################# Time Conversion Functions ########################## */
/*
Except for the strftime function, these functions each return a pointer to
one of two types of static objects: a broken-down time structure or an
array of char. Execution of any of the functions that return a pointer to
one of these object types may overwrite the information in any object of
the same type pointed to by the value returned from any previous call to
any of them. The implementation shall behave as if no other library
functions call these functions.
*/
/** The asctime function converts the broken-down time in the structure pointed
to by timeptr into a string in the form
Sun Sep 16 01:03:52 1973\n\0
using the equivalent of the following algorithm.
char *asctime(const struct tm *timeptr)
{
static const char wday_name[7][3] = {
"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
};
static const char mon_name[12][3] = {
"Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
};
static char result[26];
sprintf(result, "%.3s %.3s%3d %.2d:%.2d:%.2d %d\n",
wday_name[timeptr->tm_wday],
mon_name[timeptr->tm_mon],
timeptr->tm_mday, timeptr->tm_hour,
timeptr->tm_min, timeptr->tm_sec,
1900 + timeptr->tm_year);
return result;
}
@return The asctime function returns a pointer to the string.
**/
char *
{
register const char * wn;
register const char * mn;
wn = "???";
mn = "???";
/*
** The X3J11-suggested format is
** "%.3s %.3s%3d %02.2d:%02.2d:%02.2d %d\n"
** Since the .2 in 02.2d is ignored, we drop it.
*/
sizeof (char[ASCTIME_BUFLEN]),
"%.3s %.3s%3d %02d:%02d:%02d %d\r\n", // explicit CRLF for EFI
}
/**
**/
char *
{
}
/*
** gmtsub is to gmtime as localsub is to localtime.
*/
void
const long offset,
)
{
#ifdef _REENTRANT
#endif
if (!gmt_is_set) {
gmt_is_set = TRUE;
#ifdef ALL_STATE
#endif /* defined ALL_STATE */
}
#ifdef TM_ZONE
/*
** Could get fancy here and deliver something such as
** "UTC+xxxx" or "UTC-xxxx" if offset is non-zero,
** but this is no time for a treasure hunt.
*/
if (offset != 0)
else {
#ifdef ALL_STATE
#endif /* defined ALL_STATE */
#ifndef ALL_STATE
#endif /* State Farm */
}
#endif /* defined TM_ZONE */
}
/**
**/
struct tm *
{
}
static void
{
register int i;
#ifdef ALL_STATE
return;
}
#endif /* defined ALL_STATE */
i = 0;
i = 0;
break;
}
} else {
break;
}
/*
** To get (wrong) behavior that's compatible with System V Release 2.0
** you'd replace the statement below with
** t += ttisp->tt_gmtoff;
** timesub(&t, 0L, sp, tmp);
*/
#ifdef TM_ZONE
#endif /* defined TM_ZONE */
}
/**
**/
struct tm *
{
tzset();
}