#### 61 lines 2.1 KiB C Raw Normal View History

 2002-09-16 01:09:56 +00:00 ```#ifndef TAI_H ``` ```#define TAI_H ``` ``` ``` 2002-09-16 23:49:15 +00:00 `/* Times with 1 second precision */` ``` ``` 2002-09-16 01:09:56 +00:00 ```#include "uint64.h" ``` ``` ``` 2002-09-16 23:49:15 +00:00 ```/* A struct tai value is an integer between 0 inclusive and 2^64 ``` ` * exclusive. The format of struct tai is designed to speed up common` ` * operations; applications should not look inside struct tai.` ` *` ` * A struct tai variable is commonly used to store a TAI64 label. Each` ` * TAI64 label refers to one second of real time. TAI64 labels span a` ` * range of hundreds of billions of years.` ` *` ` * A struct tai variable may also be used to store the numerical` ` * difference between two TAI64 labels.` ``` * See http://cr.yp.to/libtai/tai64.html */ ``` ``` ``` `typedef struct tai {` 2002-09-16 01:09:56 +00:00 ` uint64 x;` `} tai64;` 2002-09-16 01:09:56 +00:00 ``` ``` 2002-09-16 23:49:15 +00:00 ``` ``` 2002-09-16 01:09:56 +00:00 ```#define tai_unix(t,u) ((void) ((t)->x = 4611686018427387914ULL + (uint64) (u))) ``` ``` ``` 2002-09-16 23:49:15 +00:00 ```/* tai_now puts the current time into t. More precisely: tai_now puts ``` ` * into t its best guess as to the TAI64 label for the 1-second interval` ` * that contains the current time.` ` *` ` * This implementation of tai_now assumes that the time_t returned from` ` * the time function represents the number of TAI seconds since` ` * 1970-01-01 00:00:10 TAI. This matches the convention used by the` ` * Olson tz library in ``right'' mode. */` 2003-09-06 23:49:47 +00:00 `void tai_now(struct tai *);` 2002-09-16 01:09:56 +00:00 ``` ``` 2002-09-16 23:49:15 +00:00 ```/* tai_approx returns a double-precision approximation to t. The result ``` ` * of tai_approx is always nonnegative. */` 2002-09-16 01:09:56 +00:00 ```#define tai_approx(t) ((double) ((t)->x)) ``` ``` ``` 2002-09-16 23:49:15 +00:00 ```/* tai_add adds a to b modulo 2^64 and puts the result into t. The ``` ` * inputs and output may overlap. */` 2003-09-06 23:49:47 +00:00 `void tai_add(struct tai *,const struct tai *,const struct tai *);` 2002-09-16 23:49:15 +00:00 ```/* tai_sub subtracts b from a modulo 2^64 and puts the result into t. ``` ` * The inputs and output may overlap. */` 2003-09-06 23:49:47 +00:00 `void tai_sub(struct tai *,const struct tai *,const struct tai *);` 2002-09-16 23:49:15 +00:00 `/* tai_less returns 1 if a is less than b, 0 otherwise. */` 2002-09-16 01:09:56 +00:00 ```#define tai_less(t,u) ((t)->x < (u)->x) ``` ``` ``` ```#define TAI_PACK 8 ``` 2002-09-16 23:49:15 +00:00 ```/* tai_pack converts a TAI64 label from internal format in t to external ``` ` * TAI64 format in buf. */` 2003-09-06 23:49:47 +00:00 `void tai_pack(char *,const struct tai *);` 2002-09-16 23:49:15 +00:00 ```/* tai_unpack converts a TAI64 label from external TAI64 format in buf ``` ` * to internal format in t. */` 2003-09-06 23:49:47 +00:00 `void tai_unpack(const char *,struct tai *);` 2002-09-16 01:09:56 +00:00 ``` ``` 2003-09-06 23:49:47 +00:00 `void tai_uint(struct tai *,unsigned int);` 2002-09-16 01:09:56 +00:00 ``` ``` ```#endif ```