Mirror of :pserver:cvs@cvs.fefe.de:/cvs libowfat https://www.fefe.de/libowfat/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

70 lines
2.3 KiB

  1. /* this header file comes from libowfat, http://www.fefe.de/libowfat/ */
  2. #ifndef TAI_H
  3. #define TAI_H
  4. /* Times with 1 second precision */
  5. #include "uint64.h"
  6. #ifdef __cplusplus
  7. extern "C" {
  8. #endif
  9. /* A struct tai value is an integer between 0 inclusive and 2^64
  10. * exclusive. The format of struct tai is designed to speed up common
  11. * operations; applications should not look inside struct tai.
  12. *
  13. * A struct tai variable is commonly used to store a TAI64 label. Each
  14. * TAI64 label refers to one second of real time. TAI64 labels span a
  15. * range of hundreds of billions of years.
  16. *
  17. * A struct tai variable may also be used to store the numerical
  18. * difference between two TAI64 labels.
  19. * See http://cr.yp.to/libtai/tai64.html */
  20. typedef struct tai {
  21. uint64 x;
  22. } tai64;
  23. #define tai_unix(t,u) ((void) ((t)->x = 4611686018427387914ULL + (uint64) (u)))
  24. /* tai_now puts the current time into t. More precisely: tai_now puts
  25. * into t its best guess as to the TAI64 label for the 1-second interval
  26. * that contains the current time.
  27. *
  28. * This implementation of tai_now assumes that the time_t returned from
  29. * the time function represents the number of TAI seconds since
  30. * 1970-01-01 00:00:10 TAI. This matches the convention used by the
  31. * Olson tz library in ``right'' mode. */
  32. void tai_now(struct tai *);
  33. /* tai_approx returns a double-precision approximation to t. The result
  34. * of tai_approx is always nonnegative. */
  35. #define tai_approx(t) ((double) ((t)->x))
  36. /* tai_add adds a to b modulo 2^64 and puts the result into t. The
  37. * inputs and output may overlap. */
  38. void tai_add(struct tai *,const struct tai *,const struct tai *);
  39. /* tai_sub subtracts b from a modulo 2^64 and puts the result into t.
  40. * The inputs and output may overlap. */
  41. void tai_sub(struct tai *,const struct tai *,const struct tai *);
  42. /* tai_less returns 1 if a is less than b, 0 otherwise. */
  43. #define tai_less(t,u) ((t)->x < (u)->x)
  44. #define TAI_PACK 8
  45. /* tai_pack converts a TAI64 label from internal format in t to external
  46. * TAI64 format in buf. */
  47. void tai_pack(char *,const struct tai *);
  48. /* tai_unpack converts a TAI64 label from external TAI64 format in buf
  49. * to internal format in t. */
  50. void tai_unpack(const char *,struct tai *);
  51. void tai_uint(struct tai *,unsigned int);
  52. #ifdef __cplusplus
  53. }
  54. #endif
  55. #endif