1 /* Copyright (c) 2012, David Goulet <dgoulet@ev0ke.net> 2 * Jacob Appelbaum <jacob@torproject.org> 3 * Copyright (c) 2012, The Tor Project, Inc. */ 4 /* See LICENSE for licensing information */ 5 6 /** 7 * \file clock.h 8 * \brief Header file for the clock primitives. 9 **/ 10 11 #pragma once 12 #ifndef CLOCK_HEADER_GUARD 13 #define CLOCK_HEADER_GUARD 1 14 15 #include <src/visibility.h> 16 17 #ifdef HAVE_TIME_H 18 #include <time.h> 19 #endif 20 21 #ifdef TARGET_OS_OPENBSD 22 #include <sys/time.h> 23 #endif 24 25 #ifdef HAVE_MACH_CLOCK_H 26 #include <mach/clock.h> 27 #endif 28 #ifdef HAVE_MACH_MACH_H 29 #include <mach/mach.h> 30 #endif 31 32 struct tlsdate_time { 33 #if defined(__linux__) || defined(__FreeBSD__) || defined (__NetBSD__) || defined (__OpenBSD__) || defined (__DragonFly__) 34 struct timespec tp; 35 #elif defined(__APPLE__) 36 mach_timespec_t tp; 37 #elif _WIN32 38 void *tp; 39 #elif TARGET_OS_HAIKU 40 struct timespec tp; 41 #elif TARGET_OS_CYGWIN 42 struct timespec tp; 43 #elif TARGET_OS_MINGW 44 struct timespec tp; 45 #elif TARGET_OS_GNUHURD 46 struct timespec tp; 47 #else 48 struct timespec tp; 49 #endif 50 }; 51 52 TLSDATE_API 53 int clock_get_real_time(struct tlsdate_time *time); 54 55 TLSDATE_API 56 int clock_set_real_time(const struct tlsdate_time *time); 57 58 TLSDATE_API 59 void clock_init_time(struct tlsdate_time *time, time_t sec, long nsec); 60 61 /* Helper macros to access time values */ 62 #define CLOCK_SEC(time) ((time)->tp.tv_sec) 63 #define CLOCK_MSEC(time) ((time)->tp.tv_nsec / 1000000) 64 #define CLOCK_USEC(time) ((time)->tp.tv_nsec / 1000) 65 #define CLOCK_NSEC(time) ((time)->tp.tv_nsec) 66 67 /* Helper macros to access time values. TODO: Complete them */ 68 /* 69 #define CLOCK_SEC(time) 70 #define CLOCK_MSEC(time) 71 #define CLOCK_USEC(time) 72 #define CLOCK_NSEC(time) 73 */ 74 #endif // CLOCK_HEADER_GUARD 75