Imported Upstream version 1.2.0
[platform/upstream/iotivity.git] / resource / csdk / connectivity / lib / libcoap-4.1.1 / include / coap / coap_time.h
@@ -34,6 +34,9 @@ extern "C"
 #ifdef HAVE_TIME_H
 #include <time.h>
 #endif
+#ifdef HAVE_SYS_TIME_H
+#include <sys/time.h>
+#endif
 #ifdef WITH_LWIP
 
 #include <stdint.h>
@@ -44,12 +47,12 @@ extern "C"
 
     typedef uint32_t coap_tick_t;
 
-    static inline void coap_ticks_impl(coap_tick_t *t)
+    INLINE_API void coap_ticks_impl(coap_tick_t *t)
     {
         *t = sys_now();
     }
 
-    static inline void coap_clock_init_impl(void)
+    INLINE_API void coap_clock_init_impl(void)
     {
     }
 
@@ -75,7 +78,7 @@ extern "C"
     /** Set at startup to initialize the internal clock (time in seconds). */
     extern clock_time_t clock_offset;
 
-    static inline void
+    INLINE_API void
     contiki_clock_init_impl(void)
     {
         clock_init();
@@ -84,7 +87,7 @@ extern "C"
 
 #define coap_clock_init contiki_clock_init_impl
 
-    static inline void
+    INLINE_API void
     contiki_ticks_impl(coap_tick_t *t)
     {
         *t = clock_time();
@@ -93,7 +96,7 @@ extern "C"
 #define coap_ticks contiki_ticks_impl
 
 #endif /* WITH_CONTIKI */
-#ifdef WITH_POSIX
+#if defined(WITH_POSIX) || defined(_WIN32)
     typedef unsigned int coap_tick_t;
 
     /**
@@ -107,7 +110,7 @@ extern "C"
 
     /** Set at startup to initialize the internal clock (time in seconds). */
     extern time_t clock_offset;
-#endif /* WITH_POSIX */
+#endif /* WITH_POSIX || _WIN32 */
 
 #ifdef WITH_ARDUINO
 #include "Time.h"
@@ -134,7 +137,7 @@ extern time_t clock_offset;
 #endif /* WITH_ARDUINO */
 
 #ifndef coap_clock_init
-    static inline void coap_clock_init_impl(void)
+    INLINE_API void coap_clock_init_impl(void)
     {
 #ifdef HAVE_TIME_H
         clock_offset = time(NULL);
@@ -159,7 +162,7 @@ extern time_t clock_offset;
 #endif /* coap_clock_init */
 
 #ifndef coap_ticks
-    static inline void coap_ticks_impl(coap_tick_t *t)
+    INLINE_API void coap_ticks_impl(coap_tick_t *t)
     {
 #ifdef HAVE_SYS_TIME_H
         struct timeval tv;
@@ -176,7 +179,12 @@ extern time_t clock_offset;
 #endif
     *t = (tv - clock_offset) * COAP_TICKS_PER_SECOND;
 #  else
+#ifdef HAVE_TIME_H
+    time_t tv = time(NULL);
+    *t = difftime(tv, clock_offset) * COAP_TICKS_PER_SECOND;
+#else
 #    error "clock not implemented"
+#endif /* HAVE_TIME_H */
 #  endif /* WITH_ARDUINO */
 #endif /* HAVE_SYS_TIME_H */
 }
@@ -187,7 +195,7 @@ extern time_t clock_offset;
      * Returns @c 1 if and only if @p a is less than @p b where less is
      * defined on a signed data type.
      */
-    static inline
+    INLINE_API
     int coap_time_lt(coap_tick_t a, coap_tick_t b)
     {
         return ((coap_tick_diff_t)(a - b)) < 0;
@@ -197,7 +205,7 @@ extern time_t clock_offset;
      * Returns @c 1 if and only if @p a is less than or equal @p b where
      * less is defined on a signed data type.
      */
-    static inline
+    INLINE_API
     int coap_time_le(coap_tick_t a, coap_tick_t b)
     {
         return a == b || coap_time_lt(a, b);