Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-08-27 09:37:33

0001 /**
0002  * \file platform_time.h
0003  *
0004  * \brief Mbed TLS Platform time abstraction
0005  */
0006 /*
0007  *  Copyright The Mbed TLS Contributors
0008  *  SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later
0009  */
0010 #ifndef MBEDTLS_PLATFORM_TIME_H
0011 #define MBEDTLS_PLATFORM_TIME_H
0012 
0013 #include "mbedtls/build_info.h"
0014 
0015 #ifdef __cplusplus
0016 extern "C" {
0017 #endif
0018 
0019 /*
0020  * The time_t datatype
0021  */
0022 #if defined(MBEDTLS_PLATFORM_TIME_TYPE_MACRO)
0023 typedef MBEDTLS_PLATFORM_TIME_TYPE_MACRO mbedtls_time_t;
0024 #else
0025 /* For time_t */
0026 #include <time.h>
0027 typedef time_t mbedtls_time_t;
0028 #endif /* MBEDTLS_PLATFORM_TIME_TYPE_MACRO */
0029 
0030 #if defined(MBEDTLS_PLATFORM_MS_TIME_TYPE_MACRO)
0031 typedef MBEDTLS_PLATFORM_MS_TIME_TYPE_MACRO mbedtls_ms_time_t;
0032 #else
0033 #include <stdint.h>
0034 #include <inttypes.h>
0035 typedef int64_t mbedtls_ms_time_t;
0036 #endif /* MBEDTLS_PLATFORM_MS_TIME_TYPE_MACRO */
0037 
0038 /**
0039  * \brief   Get time in milliseconds.
0040  *
0041  * \return Monotonically-increasing current time in milliseconds.
0042  *
0043  * \note Define MBEDTLS_PLATFORM_MS_TIME_ALT to be able to provide an
0044  *       alternative implementation
0045  *
0046  * \warning This function returns a monotonically-increasing time value from a
0047  *          start time that will differ from platform to platform, and possibly
0048  *          from run to run of the process.
0049  *
0050  */
0051 mbedtls_ms_time_t mbedtls_ms_time(void);
0052 
0053 /*
0054  * The function pointers for time
0055  */
0056 #if defined(MBEDTLS_PLATFORM_TIME_ALT)
0057 extern mbedtls_time_t (*mbedtls_time)(mbedtls_time_t *time);
0058 
0059 /**
0060  * \brief   Set your own time function pointer
0061  *
0062  * \param   time_func   the time function implementation
0063  *
0064  * \return              0
0065  */
0066 int mbedtls_platform_set_time(mbedtls_time_t (*time_func)(mbedtls_time_t *time));
0067 #else
0068 #if defined(MBEDTLS_PLATFORM_TIME_MACRO)
0069 #define mbedtls_time    MBEDTLS_PLATFORM_TIME_MACRO
0070 #else
0071 #define mbedtls_time   time
0072 #endif /* MBEDTLS_PLATFORM_TIME_MACRO */
0073 #endif /* MBEDTLS_PLATFORM_TIME_ALT */
0074 
0075 #ifdef __cplusplus
0076 }
0077 #endif
0078 
0079 #endif /* platform_time.h */