mirror of https://github.com/ipxe/ipxe.git
[time] Define an API for getting the current time
Signed-off-by: Michael Brown <mcb30@ipxe.org>pull/6/head
parent
c130001bdf
commit
846bde90e6
|
@ -0,0 +1,12 @@
|
||||||
|
#ifndef _BITS_TIME_H
|
||||||
|
#define _BITS_TIME_H
|
||||||
|
|
||||||
|
/** @file
|
||||||
|
*
|
||||||
|
* i386-specific time API implementations
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
FILE_LICENCE ( GPL2_OR_LATER );
|
||||||
|
|
||||||
|
#endif /* _BITS_TIME_H */
|
|
@ -0,0 +1,12 @@
|
||||||
|
#ifndef _BITS_TIME_H
|
||||||
|
#define _BITS_TIME_H
|
||||||
|
|
||||||
|
/** @file
|
||||||
|
*
|
||||||
|
* x86_64-specific time API implementations
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
FILE_LICENCE ( GPL2_OR_LATER );
|
||||||
|
|
||||||
|
#endif /* _BITS_TIME_H */
|
|
@ -18,6 +18,7 @@
|
||||||
#define SANBOOT_NULL
|
#define SANBOOT_NULL
|
||||||
#define BOFM_EFI
|
#define BOFM_EFI
|
||||||
#define ENTROPY_NULL
|
#define ENTROPY_NULL
|
||||||
|
#define TIME_NULL
|
||||||
|
|
||||||
#define IMAGE_EFI /* EFI image support */
|
#define IMAGE_EFI /* EFI image support */
|
||||||
#define IMAGE_SCRIPT /* iPXE script image support */
|
#define IMAGE_SCRIPT /* iPXE script image support */
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
#define SMBIOS_LINUX
|
#define SMBIOS_LINUX
|
||||||
#define SANBOOT_NULL
|
#define SANBOOT_NULL
|
||||||
#define ENTROPY_LINUX
|
#define ENTROPY_LINUX
|
||||||
|
#define TIME_NULL
|
||||||
|
|
||||||
#define DRIVERS_LINUX
|
#define DRIVERS_LINUX
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,7 @@ FILE_LICENCE ( GPL2_OR_LATER );
|
||||||
#define SMBIOS_PCBIOS
|
#define SMBIOS_PCBIOS
|
||||||
#define SANBOOT_PCBIOS
|
#define SANBOOT_PCBIOS
|
||||||
#define ENTROPY_RTC
|
#define ENTROPY_RTC
|
||||||
|
#define TIME_NULL
|
||||||
|
|
||||||
#define IMAGE_ELF /* ELF image support */
|
#define IMAGE_ELF /* ELF image support */
|
||||||
#define IMAGE_MULTIBOOT /* MultiBoot image support */
|
#define IMAGE_MULTIBOOT /* MultiBoot image support */
|
||||||
|
|
|
@ -0,0 +1,16 @@
|
||||||
|
#ifndef CONFIG_TIME_H
|
||||||
|
#define CONFIG_TIME_H
|
||||||
|
|
||||||
|
/** @file
|
||||||
|
*
|
||||||
|
* Time API configuration
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
FILE_LICENCE ( GPL2_OR_LATER );
|
||||||
|
|
||||||
|
#include <config/defaults.h>
|
||||||
|
|
||||||
|
#include <config/local/time.h>
|
||||||
|
|
||||||
|
#endif /* CONFIG_TIME_H */
|
|
@ -0,0 +1,29 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2012 Michael Brown <mbrown@fensystems.co.uk>.
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or
|
||||||
|
* modify it under the terms of the GNU General Public License as
|
||||||
|
* published by the Free Software Foundation; either version 2 of the
|
||||||
|
* License, or any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful, but
|
||||||
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||||
|
* General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
FILE_LICENCE ( GPL2_OR_LATER );
|
||||||
|
|
||||||
|
/** @file
|
||||||
|
*
|
||||||
|
* Nonexistent time source
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <ipxe/time.h>
|
||||||
|
|
||||||
|
PROVIDE_TIME_INLINE ( null, time_now );
|
|
@ -0,0 +1,23 @@
|
||||||
|
#ifndef _IPXE_NULL_TIME_H
|
||||||
|
#define _IPXE_NULL_TIME_H
|
||||||
|
|
||||||
|
/** @file
|
||||||
|
*
|
||||||
|
* Nonexistent time source
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
FILE_LICENCE ( GPL2_OR_LATER );
|
||||||
|
|
||||||
|
#ifdef TIME_NULL
|
||||||
|
#define TIME_PREFIX_null
|
||||||
|
#else
|
||||||
|
#define TIME_PREFIX_null __null_
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static inline __always_inline time_t
|
||||||
|
TIME_INLINE ( null, time_now ) ( void ) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* _IPXE_NULL_TIME_H */
|
|
@ -0,0 +1,58 @@
|
||||||
|
#ifndef _IPXE_TIME_H
|
||||||
|
#define _IPXE_TIME_H
|
||||||
|
|
||||||
|
/** @file
|
||||||
|
*
|
||||||
|
* Time source
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
FILE_LICENCE ( GPL2_OR_LATER );
|
||||||
|
|
||||||
|
#include <sys/time.h>
|
||||||
|
#include <ipxe/api.h>
|
||||||
|
#include <config/time.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Calculate static inline time API function name
|
||||||
|
*
|
||||||
|
* @v _prefix Subsystem prefix
|
||||||
|
* @v _api_func API function
|
||||||
|
* @ret _subsys_func Subsystem API function
|
||||||
|
*/
|
||||||
|
#define TIME_INLINE( _subsys, _api_func ) \
|
||||||
|
SINGLE_API_INLINE ( TIME_PREFIX_ ## _subsys, _api_func )
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provide a time API implementation
|
||||||
|
*
|
||||||
|
* @v _prefix Subsystem prefix
|
||||||
|
* @v _api_func API function
|
||||||
|
* @v _func Implementing function
|
||||||
|
*/
|
||||||
|
#define PROVIDE_TIME( _subsys, _api_func, _func ) \
|
||||||
|
PROVIDE_SINGLE_API ( TIME_PREFIX_ ## _subsys, _api_func, _func )
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provide a static inline time API implementation
|
||||||
|
*
|
||||||
|
* @v _prefix Subsystem prefix
|
||||||
|
* @v _api_func API function
|
||||||
|
*/
|
||||||
|
#define PROVIDE_TIME_INLINE( _subsys, _api_func ) \
|
||||||
|
PROVIDE_SINGLE_API_INLINE ( TIME_PREFIX_ ## _subsys, _api_func )
|
||||||
|
|
||||||
|
/* Include all architecture-independent time API headers */
|
||||||
|
#include <ipxe/null_time.h>
|
||||||
|
|
||||||
|
/* Include all architecture-dependent time API headers */
|
||||||
|
#include <bits/time.h>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get current time in seconds
|
||||||
|
*
|
||||||
|
* @ret time Time, in seconds
|
||||||
|
*/
|
||||||
|
time_t time_now ( void );
|
||||||
|
|
||||||
|
#endif /* _IPXE_TIME_H */
|
|
@ -7,6 +7,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <sys/time.h>
|
#include <sys/time.h>
|
||||||
|
#include <ipxe/time.h>
|
||||||
|
|
||||||
/** Broken-down time */
|
/** Broken-down time */
|
||||||
struct tm {
|
struct tm {
|
||||||
|
@ -30,6 +31,21 @@ struct tm {
|
||||||
int tm_isdst;
|
int tm_isdst;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get current time in seconds since the Epoch
|
||||||
|
*
|
||||||
|
* @v t Time to fill in, or NULL
|
||||||
|
* @ret time Current time
|
||||||
|
*/
|
||||||
|
static inline time_t time ( time_t *t ) {
|
||||||
|
time_t now;
|
||||||
|
|
||||||
|
now = time_now();
|
||||||
|
if ( t )
|
||||||
|
*t = now;
|
||||||
|
return now;
|
||||||
|
}
|
||||||
|
|
||||||
extern time_t mktime ( struct tm *tm );
|
extern time_t mktime ( struct tm *tm );
|
||||||
|
|
||||||
#endif /* _TIME_H */
|
#endif /* _TIME_H */
|
||||||
|
|
Loading…
Reference in New Issue