summaryrefslogtreecommitdiff
path: root/src/tai.c
diff options
context:
space:
mode:
authorJannis Hoffmann <jannis@fehcom.de>2024-09-28 17:13:21 +0200
committerJannis Hoffmann <jannis@fehcom.de>2024-09-28 17:13:21 +0200
commit4ab19268268cd96b9706625d42a16d2a629134eb (patch)
tree0894a92709675955abb1b15647e8fe2911d89c7f /src/tai.c
parent96cf8dffe4f7b0b910f790066ae622dc429eb522 (diff)
update to version 25
Diffstat (limited to 'src/tai.c')
-rw-r--r--src/tai.c59
1 files changed, 59 insertions, 0 deletions
diff --git a/src/tai.c b/src/tai.c
new file mode 100644
index 0000000..5ec7652
--- /dev/null
+++ b/src/tai.c
@@ -0,0 +1,59 @@
+#include <time.h>
+#include "tai.h"
+
+/**
+ * @file tai.c
+ * @author djb
+ * @ref qmail
+ * @brief 'temps atomic' time handling
+ */
+
+void tai_add(struct tai *t,const struct tai *u,const struct tai *v)
+{
+ t->x = u->x + v->x;
+}
+
+void tai_now(struct tai *t)
+{
+ tai_unix(t,time((time_t *) 0));
+}
+
+void tai_pack(char *s,const struct tai *t)
+{
+ uint64 x;
+
+ x = t->x;
+ s[7] = (char)x; x >>= 8;
+ s[6] = (char)x; x >>= 8;
+ s[5] = (char)x; x >>= 8;
+ s[4] = (char)x; x >>= 8;
+ s[3] = (char)x; x >>= 8;
+ s[2] = (char)x; x >>= 8;
+ s[1] = (char)x; x >>= 8;
+ s[0] = (char)x;
+}
+
+void tai_sub(struct tai *t,const struct tai *u,const struct tai *v)
+{
+ t->x = u->x - v->x;
+}
+
+void tai_uint(struct tai *t,unsigned int u)
+{
+ t->x = u;
+}
+
+void tai_unpack(const char *s,struct tai *t)
+{
+ uint64 x;
+
+ x = (unsigned char) s[0];
+ x <<= 8; x += (unsigned char) s[1];
+ x <<= 8; x += (unsigned char) s[2];
+ x <<= 8; x += (unsigned char) s[3];
+ x <<= 8; x += (unsigned char) s[4];
+ x <<= 8; x += (unsigned char) s[5];
+ x <<= 8; x += (unsigned char) s[6];
+ x <<= 8; x += (unsigned char) s[7];
+ t->x = x;
+}