1 /* Copyright (c) 2012, David Goulet <dgoulet@ev0ke.net> 2 * Jacob Appelbaum 3 * Copyright (c) 2012, The Tor Project, Inc. */ 4 /* See LICENSE for licensing information */ 5 6 /** 7 * \file clock-linux.c 8 * \brief Contains clock primitives for GNU/Linux OS 9 **/ 10 11 #include "config.h" 12 13 #include <assert.h> 14 15 #include "src/compat/clock.h" 16 17 /** 18 * Get current real time value and store it into time. 19 * 20 * @param time where the current time is stored 21 * @return clock_gettime syscall return value 22 */ clock_get_real_time(struct tlsdate_time * time)23int clock_get_real_time(struct tlsdate_time *time) 24 { 25 /* Safety net */ 26 assert (time); 27 return clock_gettime (CLOCK_REALTIME, &time->tp); 28 } 29 30 /** 31 * Set current real time clock using time. 32 * 33 * @param time where the current time to set is stored 34 * @return clock_settime syscall return value 35 */ clock_set_real_time(const struct tlsdate_time * time)36int clock_set_real_time(const struct tlsdate_time *time) 37 { 38 /* Safety net */ 39 assert (time); 40 return clock_settime (CLOCK_REALTIME, &time->tp); 41 } 42 43 /** 44 * Init a tlsdate_time structure. 45 * 46 * @param sec is the seconds 47 * @param nsec is the nanoseconds 48 */ clock_init_time(struct tlsdate_time * time,time_t sec,long nsec)49void clock_init_time(struct tlsdate_time *time, time_t sec, 50 long nsec) 51 { 52 /* Safety net */ 53 assert (time); 54 time->tp.tv_sec = sec; 55 time->tp.tv_nsec = nsec; 56 } 57