diff options
author | darylm503 <darylm503@6f19259b-4bc3-4df7-8a09-765794883524> | 2011-07-30 00:30:44 +0000 |
---|---|---|
committer | darylm503 <darylm503@6f19259b-4bc3-4df7-8a09-765794883524> | 2011-07-30 00:30:44 +0000 |
commit | d7ce700605e1af0e455e31ec11f19ff21d26b525 (patch) | |
tree | 243b582ac3350e8c6ce6ca96fff13805318fd65c /StdLib/LibC/Time | |
parent | f766dd76fde231ecd4f2e9faf99293e90902cebb (diff) | |
download | edk2-platforms-d7ce700605e1af0e455e31ec11f19ff21d26b525.tar.xz |
Add Socket Libraries.
Add Posix functions for porting compatibility.
Fix compliance issues with ISO/IEC 9899:199409
New Functions:
setenv(), fparseln(), GetFileNameFromPath(), rename(),
realpath(), setprogname(), getprogname(), strlcat(), strlcpy(),
strsep(), setitimer(), getitimer(), timegm(), getopt(), basename(),
mkstemp(), ffs(), vsnprintf(), snprintf(), getpass(), usleep(), select(),
writev(), strcasecmp(), getcwd(), chdir(), tcgetpgrp(), getpgrp(), gettimeofday(),
bcopy(),
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@12061 6f19259b-4bc3-4df7-8a09-765794883524
Diffstat (limited to 'StdLib/LibC/Time')
-rw-r--r-- | StdLib/LibC/Time/Time.c | 17 | ||||
-rw-r--r-- | StdLib/LibC/Time/Time.inf | 2 | ||||
-rw-r--r-- | StdLib/LibC/Time/TimeEfi.c | 2 | ||||
-rw-r--r-- | StdLib/LibC/Time/TimeVals.h | 4 | ||||
-rw-r--r-- | StdLib/LibC/Time/ZoneProc.c | 2 | ||||
-rw-r--r-- | StdLib/LibC/Time/gettimeofday.c | 1 | ||||
-rw-r--r-- | StdLib/LibC/Time/itimer.c | 277 | ||||
-rw-r--r-- | StdLib/LibC/Time/strftime.c | 10 | ||||
-rw-r--r-- | StdLib/LibC/Time/timegm.c | 113 |
9 files changed, 401 insertions, 27 deletions
diff --git a/StdLib/LibC/Time/Time.c b/StdLib/LibC/Time/Time.c index 5cb9347752..e3eccb593b 100644 --- a/StdLib/LibC/Time/Time.c +++ b/StdLib/LibC/Time/Time.c @@ -82,7 +82,6 @@ static void localsub(const time_t * const timep, const long offset, struct tm * const tmp);
clock_t
-EFIAPI
__getCPS(void)
{
return gMD->ClocksPerSecond;
@@ -183,7 +182,7 @@ timesub( /** The clock function determines the processor time used.
- @return The clock function returns the implementation’s best
+ @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
@@ -196,7 +195,6 @@ timesub( CPU TimeStamp Counter ticks since the appliation started.
**/
clock_t
-EFIAPI
clock(void)
{
#ifndef NT32dvm
@@ -213,7 +211,6 @@ clock(void) /**
**/
double
-EFIAPI
difftime(time_t time1, time_t time0)
{
return (double)(time1 - time0);
@@ -429,7 +426,7 @@ time2sub( return t;
}
-static time_t
+time_t
time2(struct tm * const tmp, void (* const funcp)(const time_t*, long, struct tm*),
const long offset, int * const okayp)
{
@@ -542,7 +539,6 @@ time1( represented, the function returns the value (time_t)(-1).
**/
time_t
-EFIAPI
mktime(struct tm *timeptr)
{
/* From NetBSD */
@@ -558,14 +554,13 @@ mktime(struct tm *timeptr) /** 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
+ @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.
**/
time_t
-EFIAPI
time(time_t *timer)
{
time_t CalTime;
@@ -633,7 +628,6 @@ time(time_t *timer) @return The asctime function returns a pointer to the string.
**/
char *
-EFIAPI
asctime(const struct tm *timeptr)
{
register const char * wn;
@@ -663,7 +657,6 @@ asctime(const struct tm *timeptr) /**
**/
char *
-EFIAPI
ctime(const time_t *timer)
{
return asctime(localtime(timer));
@@ -672,7 +665,7 @@ ctime(const time_t *timer) /*
** gmtsub is to gmtime as localsub is to localtime.
*/
-static void
+void
gmtsub(
const time_t * const timep,
const long offset,
@@ -718,7 +711,6 @@ gmtsub( /**
**/
struct tm *
-EFIAPI
gmtime(const time_t *timer)
{
gmtsub(timer, 0L, &gMD->BDTime);
@@ -771,7 +763,6 @@ localsub(const time_t * const timep, const long offset, struct tm * const tmp) /**
**/
struct tm *
-EFIAPI
localtime(const time_t *timer)
{
tzset();
diff --git a/StdLib/LibC/Time/Time.inf b/StdLib/LibC/Time/Time.inf index 6de494f8d4..3ad226951d 100644 --- a/StdLib/LibC/Time/Time.inf +++ b/StdLib/LibC/Time/Time.inf @@ -32,6 +32,8 @@ strptime.c
TimeEfi.c
gettimeofday.c
+ timegm.c
+ itimer.c
[Packages]
StdLib/StdLib.dec
diff --git a/StdLib/LibC/Time/TimeEfi.c b/StdLib/LibC/Time/TimeEfi.c index 7b062c917b..8c033fd7d9 100644 --- a/StdLib/LibC/Time/TimeEfi.c +++ b/StdLib/LibC/Time/TimeEfi.c @@ -21,7 +21,6 @@ /* Convert an EFI_TIME structure into a C Standard tm structure. */
void
-EFIAPI
Efi2Tm( EFI_TIME *ET, struct tm *BT)
{
// Convert EFI time to broken-down time.
@@ -39,7 +38,6 @@ Efi2Tm( EFI_TIME *ET, struct tm *BT) /* Convert an EFI_TIME structure into a time_t value. */
time_t
-EFIAPI
Efi2Time( EFI_TIME *EfiBDtime)
{
Efi2Tm( EfiBDtime, &gMD->BDTime);
diff --git a/StdLib/LibC/Time/TimeVals.h b/StdLib/LibC/Time/TimeVals.h index 72827f9a91..f84f4f612a 100644 --- a/StdLib/LibC/Time/TimeVals.h +++ b/StdLib/LibC/Time/TimeVals.h @@ -110,8 +110,8 @@ struct rule { #define MONTH_NTH_DAY_OF_WEEK 2 /* Mm.n.d - month, week, day of week */
__BEGIN_DECLS
-extern void EFIAPI gmtload(struct state * const sp);
-extern void EFIAPI tzset(void);
+extern void gmtload(struct state * const sp);
+extern void tzset(void);
__END_DECLS
#endif /* _TIMEVAL_H */
diff --git a/StdLib/LibC/Time/ZoneProc.c b/StdLib/LibC/Time/ZoneProc.c index e33b99ed68..a7b589b7df 100644 --- a/StdLib/LibC/Time/ZoneProc.c +++ b/StdLib/LibC/Time/ZoneProc.c @@ -761,7 +761,6 @@ tzparse( }
void
-EFIAPI
gmtload(struct state * const sp)
{
if (tzload(gmt, sp) != 0)
@@ -788,7 +787,6 @@ tzsetwall(void) }
void
-EFIAPI
tzset(void)
{
register const char * name;
diff --git a/StdLib/LibC/Time/gettimeofday.c b/StdLib/LibC/Time/gettimeofday.c index 1c379a6b97..b26d157684 100644 --- a/StdLib/LibC/Time/gettimeofday.c +++ b/StdLib/LibC/Time/gettimeofday.c @@ -44,7 +44,6 @@ Heimdal: gettimeofday.c 14773 2005-04-12 11:29:18Z lha $
NetBSD: gettimeofday.c,v 1.2 2008/03/22 08:37:21 mlelstv Exp $
**/
-
#include <LibConfig.h>
#include <sys/EfiCdefs.h>
#include <sys/time.h>
diff --git a/StdLib/LibC/Time/itimer.c b/StdLib/LibC/Time/itimer.c new file mode 100644 index 0000000000..d6f6ab44c0 --- /dev/null +++ b/StdLib/LibC/Time/itimer.c @@ -0,0 +1,277 @@ +/** @file
+ setitimer and getitimer functions.
+
+ Copyright (c) 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
+ http://opensource.org/licenses/bsd-license.php.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+**/
+#include <LibConfig.h>
+#include <sys/EfiSysCall.h>
+#include <sys/time.h>
+#include <time.h>
+#include <errno.h>
+#include <sys/signal.h>
+#include <signal.h>
+#include <Library/UefiBootServicesTableLib.h>
+#include <Library/BaseMemoryLib.h>
+#include <Library/UefiLib.h>
+
+STATIC EFI_EVENT RealTimer = NULL;
+STATIC EFI_EVENT VirtualTimer = NULL;
+STATIC EFI_EVENT ProfTimer = NULL;
+
+STATIC struct itimerval RealTimerInfo = {{0,0},{0,0}};
+STATIC struct itimerval VirtualTimerInfo = {{0,0},{0,0}};
+STATIC struct itimerval ProfTimerInfo = {{0,0},{0,0}};
+
+/**
+ Function to queue the next iteration of the timer.
+
+ This will copy the interval part of the struct into the value and (if
+ non-zero), then queue the next timer event.
+
+ @param[in] TimerInfo The timer info structure.
+ @param[in] Event The EFI timer event.
+**/
+VOID
+EFIAPI
+SetNext (
+ IN struct itimerval *TimerInfo,
+ IN EFI_EVENT Event
+ )
+{
+ EFI_STATUS Status;
+
+ CopyMem(&(TimerInfo->it_value), &(TimerInfo->it_interval), sizeof(struct timeval));
+
+ //
+ // If now zero then close and be done.
+ //
+ if (TimerInfo->it_value.tv_sec+TimerInfo->it_value.tv_usec == 0) {
+ if (Event != NULL) {
+ gBS->CloseEvent(Event);
+ Event = NULL;
+ }
+ return;
+ }
+
+ //
+ // Set up for the next loop.
+ //
+ Status = gBS->SetTimer (
+ Event,
+ TimerRelative,
+ TimerInfo->it_value.tv_sec*10000000+TimerInfo->it_value.tv_usec*1000);
+
+ if (EFI_ERROR(Status)) {
+ gBS->CloseEvent(Event);
+ Event = NULL;
+ }
+}
+
+/**
+ Notification function for real timer.
+
+ @param[in] Event The event.
+ @param[in] Context Ignored.
+**/
+VOID
+EFIAPI
+iTimerRealNotifyFunction (
+ IN EFI_EVENT Event,
+ IN VOID *Context
+ )
+{
+ raise(SIGALRM);
+ SetNext(&RealTimerInfo, RealTimer);
+}
+
+/**
+ Notification function for virtual timer.
+
+ @param[in] Event The event.
+ @param[in] Context Ignored.
+**/
+VOID
+EFIAPI
+iTimerVirtualNotifyFunction (
+ IN EFI_EVENT Event,
+ IN VOID *Context
+ )
+{
+ raise(SIGVTALRM);
+ SetNext(&VirtualTimerInfo, VirtualTimer);
+}
+
+/**
+ Notification function for prof timer.
+
+ @param[in] Event The event.
+ @param[in] Context Ignored.
+**/
+VOID
+EFIAPI
+iTimerProfNotifyFunction (
+ IN EFI_EVENT Event,
+ IN VOID *Context
+ )
+{
+ raise(SIGPROF);
+ SetNext(&ProfTimerInfo, ProfTimer);
+}
+
+/**
+ The setitimer() function sets the timer specified by which to the value
+ specified in the structure pointed to by value, and if ovalue is not a null
+ pointer, stores the previous value of the timer in the structure pointed to
+ by ovalue.
+
+ A timer value is defined by the itimerval structure. If it_value is non-zero,
+ it indicates the time to the next timer expiration. If it_interval is
+ non-zero, it specifies a value to be used in reloading it_value when the
+ timer expires. Setting it_value to 0 disables a timer, regardless of the
+ value of it_interval. Setting it_interval to 0 disables a timer after its
+ next expiration (assuming it_value is non-zero).
+
+ ITIMER_REAL
+ Decrements in real time. A SIGALRM signal is delivered when this timer
+ expires.
+
+ ITIMER_VIRTUAL
+ Decrements in process virtual time. It runs only when the process is
+ executing. A SIGVTALRM signal is delivered when it expires.
+
+ ITIMER_PROF
+ Decrements both in process virtual time and when the system is running on
+ behalf of the process. It is designed to be used by interpreters in
+ statistically profiling the execution of interpreted programs. Each time
+ the ITIMER_PROF timer expires, the SIGPROF signal is delivered.
+
+ @param[in] which Which timer to set. Possible values are described above.
+ @param[in] value The new value for this timer.
+ @param[out] ovalue The old value for this timer.
+
+ @retval 0 The operation was successful.
+ @retval -1 The operation failed. see errno for more details.
+**/
+
+int setitimer(
+ int which,
+ const struct itimerval *value,
+ struct itimerval *ovalue
+ )
+{
+ EFI_EVENT *EventPointer;
+ EFI_EVENT_NOTIFY NotifyFunction;
+ EFI_STATUS Status;
+
+ if (value == NULL) {
+ errno = EINVAL;
+ return (-1);
+ }
+
+ if (which == ITIMER_REAL) {
+ EventPointer = &RealTimer;
+ NotifyFunction = iTimerRealNotifyFunction;
+ if (ovalue != NULL) {
+ CopyMem(ovalue, &RealTimerInfo, sizeof(struct itimerval));
+ }
+ CopyMem(&RealTimerInfo, value, sizeof(struct itimerval));
+ } else if (which == ITIMER_VIRTUAL) {
+ EventPointer = &VirtualTimer;
+ NotifyFunction = iTimerVirtualNotifyFunction;
+ if (ovalue != NULL) {
+ CopyMem(ovalue, &VirtualTimerInfo, sizeof(struct itimerval));
+ }
+ CopyMem(&VirtualTimerInfo, value, sizeof(struct itimerval));
+ } else if (which == ITIMER_PROF) {
+ EventPointer = &ProfTimer;
+ NotifyFunction = iTimerProfNotifyFunction;
+ if (ovalue != NULL) {
+ CopyMem(ovalue, &ProfTimerInfo, sizeof(struct itimerval));
+ }
+ CopyMem(&ProfTimerInfo, value, sizeof(struct itimerval));
+ } else {
+ errno = EINVAL;
+ return (-1);
+ }
+
+ if (*EventPointer != NULL) {
+ gBS->CloseEvent(*EventPointer);
+ *EventPointer = NULL;
+ }
+
+ //
+ // This was a 'please cancel me' request.
+ //
+ if (value->it_value.tv_sec+value->it_value.tv_usec == 0) {
+ return 0;
+ }
+
+ Status = gBS->CreateEvent (
+ EVT_TIMER|EVT_NOTIFY_SIGNAL,
+ EfiGetCurrentTpl(),
+ NotifyFunction,
+ NULL, // no context
+ EventPointer);
+
+ if (EFI_ERROR(Status)) {
+ errno = EINVAL;
+ return (-1);
+ }
+
+ Status = gBS->SetTimer (
+ *EventPointer,
+ TimerRelative,
+ value->it_value.tv_sec*10000000+value->it_value.tv_usec*1000);
+
+ if (EFI_ERROR(Status)) {
+ gBS->CloseEvent(*EventPointer);
+ *EventPointer = NULL;
+ errno = EINVAL;
+ return (-1);
+ }
+
+ return 0;
+}
+
+/**
+ Function to get the current state of a timer.
+
+ @param[in] which The identifier of the timer to get. See setitimer for
+ details.
+ @param[in] value The pointer to populate. must be pre-allocated to size.
+
+ @return 0 The operation was successful.
+ @return -1 The operation failed.
+ This means that value or which had an invalid value.
+**/
+int getitimer(
+ int which,
+ struct itimerval *value
+ )
+{
+
+ if (value == NULL) {
+ errno = EINVAL;
+ return (-1);
+ }
+
+ if (which == ITIMER_REAL) {
+ CopyMem(value, &RealTimerInfo, sizeof(struct itimerval));
+ } else if (which == ITIMER_VIRTUAL) {
+ CopyMem(value, &VirtualTimerInfo, sizeof(struct itimerval));
+ } else if (which == ITIMER_PROF) {
+ CopyMem(value, &ProfTimerInfo, sizeof(struct itimerval));
+ } else {
+ errno = EINVAL;
+ return (-1);
+ }
+
+ return 0;
+}
\ No newline at end of file diff --git a/StdLib/LibC/Time/strftime.c b/StdLib/LibC/Time/strftime.c index 6a5e2a34af..11757b6129 100644 --- a/StdLib/LibC/Time/strftime.c +++ b/StdLib/LibC/Time/strftime.c @@ -72,9 +72,9 @@ #define Locale _CurrentTimeLocale
-static char * EFIAPI _add(const char *, char *, const char * const);
-static char * EFIAPI _conv(const int, const char * const, char * const, const char * const);
-static char * EFIAPI _fmt(const char *, const struct tm * const, char *, const char * const, int *);
+static char * _add(const char *, char *, const char * const);
+static char * _conv(const int, const char * const, char * const, const char * const);
+static char * _fmt(const char *, const struct tm * const, char *, const char * const, int *);
#define NO_RUN_TIME_WARNINGS_ABOUT_YEAR_2000_PROBLEMS_THANK_YOU
@@ -89,7 +89,6 @@ static char * EFIAPI _fmt(const char *, const struct tm * const, char *, const c #define IN_ALL 3
size_t
-EFIAPI
strftime(
char * __restrict s,
size_t maxsize,
@@ -128,7 +127,6 @@ strftime( }
static char *
-EFIAPI
_fmt(
const char * format,
const struct tm * const t,
@@ -574,7 +572,6 @@ label: }
static char *
-EFIAPI
_conv(
const int n,
const char * const format,
@@ -589,7 +586,6 @@ _conv( }
static char *
-EFIAPI
_add(
const char * str,
char * pt,
diff --git a/StdLib/LibC/Time/timegm.c b/StdLib/LibC/Time/timegm.c new file mode 100644 index 0000000000..a672dc8da1 --- /dev/null +++ b/StdLib/LibC/Time/timegm.c @@ -0,0 +1,113 @@ +/** @file
+ timegm implementation
+
+ Copyright (c) 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
+ http://opensource.org/licenses/bsd-license.php.
+
+ THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
+ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
+
+ * Copyright (c) 1987, 1989 Regents of the University of California.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * Arthur David Olson of the National Cancer Institute.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the University of
+ * California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+
+static char *sccsid = "from: @(#)ctime.c 5.26 (Berkeley) 2/23/91";
+
+
+ * This implementation of mktime is lifted straight from the NetBSD (BSD 4.4)
+ * version. I modified it slightly to divorce it from the internals of the
+ * ctime library. Thus this version can't use details of the internal
+ * timezone state file to figure out strange unnormalized struct tm values,
+ * as might result from someone doing date math on the tm struct then passing
+ * it to mktime.
+ *
+ * It just does as well as it can at normalizing the tm input, then does a
+ * binary search of the time space using the system's localtime() function.
+ *
+ * The original binary search was defective in that it didn't consider the
+ * setting of tm_isdst when comparing tm values, causing the search to be
+ * flubbed for times near the dst/standard time changeover. The original
+ * code seems to make up for this by grubbing through the timezone info
+ * whenever the binary search barfed. Since I don't have that luxury in
+ * portable code, I have to take care of tm_isdst in the comparison routine.
+ * This requires knowing how many minutes offset dst is from standard time.
+ *
+ * So, if you live somewhere in the world where dst is not 60 minutes offset,
+ * and your vendor doesn't supply mktime(), you'll have to edit this variable
+ * by hand. Sorry about that.
+
+ $NetBSD: mktime.c,v 1.4 2006/06/11 19:34:10 kardel Exp $
+**/
+
+#include <LibConfig.h>
+#include <time.h>
+
+/*
+ This funciton is in Time.c, which has a different license than timegm.
+*/
+time_t
+time2(struct tm * const tmp, void (* const funcp)(const time_t*, long, struct tm*),
+ const long offset, int * const okayp);
+
+/*
+ This funciton is in Time.c, which has a different license than timegm.
+*/
+void
+gmtsub(
+ const time_t * const timep,
+ const long offset,
+ struct tm * const tmp
+ );
+
+#ifndef WRONG
+#define WRONG (-1)
+#endif /* !defined WRONG */
+
+/*
+ Convert a tm structure to a GMT based time_t.
+*/
+time_t timegm( struct tm * tmp )
+{
+ register time_t t;
+ int okay;
+
+ tmp->tm_isdst = 0;
+ t = time2(tmp, gmtsub, 0, &okay);
+ if (okay || tmp->tm_isdst < 0)
+ return t;
+
+ return WRONG;
+}
\ No newline at end of file |