libpayload: add time()

Change-Id: I97e393537ccc71ea454bb0d6cdbbb7ed32485f1e
Signed-off-by: Nicola Corna <nicola@corna.info>
Reviewed-on: https://review.coreboot.org/21011
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Nico Huber <nico.h@gmx.de>
Reviewed-by: Paul Menzel <paulepanter@users.sourceforge.net>
This commit is contained in:
Nicola Corna 2017-08-14 20:29:16 +02:00 committed by Martin Roth
parent 7f395fe95b
commit b016f144cc
2 changed files with 21 additions and 6 deletions

View File

@ -44,6 +44,7 @@ struct timeval {
suseconds_t tv_usec; /**< Microseconds */ suseconds_t tv_usec; /**< Microseconds */
}; };
time_t time(time_t *tp);
int gettimeofday(struct timeval *tv, void *tz); int gettimeofday(struct timeval *tv, void *tz);
/** @} */ /** @} */

View File

@ -121,13 +121,12 @@ static void gettimeofday_init(void)
#endif #endif
/** /**
* Return the current time broken into a timeval structure. * Return the current time expressed as seconds from 00:00:00 UTC, 1 Jan 1970.
* *
* @param tv A pointer to a timeval structure. * @param tp When not NULL, set this to the current time in seconds.
* @param tz Added for compatability - not used. * @return The current time in seconds.
* @return 0 for success (this function cannot return non-zero currently).
*/ */
int gettimeofday(struct timeval *tv, void *tz) time_t time(time_t *tp)
{ {
/* /*
* Call the gtod init when we need it - this keeps the code from * Call the gtod init when we need it - this keeps the code from
@ -138,7 +137,22 @@ int gettimeofday(struct timeval *tv, void *tz)
update_clock(); update_clock();
tv->tv_sec = clock.secs; if (tp)
*tp = clock.secs;
return clock.secs;
}
/**
* Return the current time broken into a timeval structure.
*
* @param tv A pointer to a timeval structure.
* @param tz Added for compatibility - not used.
* @return 0 for success (this function cannot return non-zero currently).
*/
int gettimeofday(struct timeval *tv, void *tz)
{
tv->tv_sec = time(NULL);
tv->tv_usec = clock.usecs; tv->tv_usec = clock.usecs;
return 0; return 0;