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 */ 23int clock_get_real_time(struct tlsdate_time *time) 24{ 25 /* Safety net */ 26 assert(time); 27 28 return clock_gettime(CLOCK_REALTIME, &time->tp); 29} 30 31/** 32 * Set current real time clock using time. 33 * 34 * @param time where the current time to set is stored 35 * @return clock_settime syscall return value 36 */ 37int clock_set_real_time(const struct tlsdate_time *time) 38{ 39 /* Safety net */ 40 assert(time); 41 42 return clock_settime(CLOCK_REALTIME, &time->tp); 43} 44 45/** 46 * Init a tlsdate_time structure. 47 * 48 * @param sec is the seconds 49 * @param nsec is the nanoseconds 50 */ 51void clock_init_time(struct tlsdate_time *time, time_t sec, 52 long nsec) 53{ 54 /* Safety net */ 55 assert(time); 56 57 time->tp.tv_sec = sec; 58 time->tp.tv_nsec = nsec; 59} 60