summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2015-10-14 22:54:08 +0000
committerLaurent Bercot <ska-skaware@skarnet.org>2015-10-14 22:54:08 +0000
commit805729e206b7586c57483aa0f4a90f7e0e2c9661 (patch)
tree4d4afb75b73cd11c953853faa48dc4cc7f236380 /tools
parent2e0421fc58922697f2bb51c428599fbd44055556 (diff)
downloadskalibs-c6ae6c046fb1653c17373bc38de3d2773e7ca807.tar.xz
- Remove /etc/leapsecs.datv2.3.8.0
- Publish tools to create the leap second table as a .c - Simplify functions using leap seconds - rc for 2.3.8.0
Diffstat (limited to 'tools')
-rw-r--r--tools/convert-leapsecs.c53
-rw-r--r--tools/leapsecs.txt29
-rwxr-xr-xtools/make-leapsecs_table39
3 files changed, 121 insertions, 0 deletions
diff --git a/tools/convert-leapsecs.c b/tools/convert-leapsecs.c
new file mode 100644
index 0000000..82410e6
--- /dev/null
+++ b/tools/convert-leapsecs.c
@@ -0,0 +1,53 @@
+#include <time.h>
+#include <skalibs/uint64.h>
+#include <skalibs/buffer.h>
+#include <skalibs/strerr2.h>
+#include <skalibs/stralloc.h>
+#include <skalibs/genalloc.h>
+#include <skalibs/skamisc.h>
+
+static genalloc table = GENALLOC_ZERO ; /* uint64 */
+
+static void add_leapsecs (uint64 *t)
+{
+ uint64 *tab = genalloc_s(uint64, &table) ;
+ unsigned int n = genalloc_len(uint64, &table) ;
+ unsigned int i = 0 ;
+ for (; i < n ; i++) if (*t >= tab[i]) (*t)++ ;
+}
+
+int main (int argc, char const *const *argv)
+{
+ stralloc sa = STRALLOC_ZERO ;
+ for (;;)
+ {
+ struct tm tm ;
+ uint64 tt ;
+ time_t t ;
+ char *p ;
+ int r ;
+ char fmt[UINT64_FMT] ;
+ sa.len = 0 ;
+ r = skagetln(buffer_0, &sa, '\n') ;
+ if (r < 0) strerr_diefu1sys(111, "read from stdin") ;
+ if (!r) break ;
+ sa.s[sa.len-1] = 0 ;
+ if (!strptime(sa.s, "+%Y-%m-%d", &tm)) continue ;
+ tm.tm_sec = 59 ;
+ tm.tm_min = 59 ;
+ tm.tm_hour = 23 ;
+ t = mktime(&tm) ;
+ if (t < 0) strerr_diefu1sys(111, "mktime") ;
+ tt = t + 10 ;
+ add_leapsecs(&tt) ;
+ if (!genalloc_append(uint64, &table, &tt))
+ strerr_diefu1sys(111, "genalloc_append") ;
+ fmt[uint64_fmt(fmt, tt)] = 0 ;
+ buffer_puts(buffer_1, " TAI_MAGIC + ") ;
+ buffer_puts(buffer_1, fmt) ;
+ buffer_puts(buffer_1, ",\n") ;
+ }
+ buffer_unput(buffer_1, 2) ;
+ buffer_putsflush(buffer_1, "\n") ;
+ return 0 ;
+}
diff --git a/tools/leapsecs.txt b/tools/leapsecs.txt
new file mode 100644
index 0000000..fa2a965
--- /dev/null
+++ b/tools/leapsecs.txt
@@ -0,0 +1,29 @@
+#
+# 1972-01-01 00:00:00 UTC was 1972-01-01 00:00:10 TAI.
+#
++1972-06-30
++1972-12-31
++1973-12-31
++1974-12-31
++1975-12-31
++1976-12-31
++1977-12-31
++1978-12-31
++1979-12-31
++1981-06-30
++1982-06-30
++1983-06-30
++1985-06-30
++1987-12-31
++1989-12-31
++1990-12-31
++1992-06-30
++1993-06-30
++1994-06-30
++1995-12-31
++1997-06-30
++1998-12-31
++2005-12-31
++2008-12-31
++2012-06-30
++2015-06-30
diff --git a/tools/make-leapsecs_table b/tools/make-leapsecs_table
new file mode 100755
index 0000000..c62fdde
--- /dev/null
+++ b/tools/make-leapsecs_table
@@ -0,0 +1,39 @@
+#!/command/execlineb -P
+
+# Compile convert-leapsecs.c, then use this to create
+# src/libstddjb/leapsecs_table.c
+
+define PREFIX ./tools
+
+backtick -n N
+{
+ pipeline
+ {
+ redirfd -r 0 ${PREFIX}/leapsecs.txt
+ ${PREFIX}/convert-leapsecs
+ }
+ wc -l
+}
+import -u N
+
+if
+{
+ s6-echo "/* ISC license. */
+
+/* MT-unsafe */
+
+#include <skalibs/uint64.h>
+#include <skalibs/tai.h>
+#include \"djbtime-internal.h\"
+
+unsigned int const leapsecs_table_len = ${N} ;
+static uint64 const leapsecs_table_[${N}] =\n{"
+}
+
+if
+{
+ redirfd -r 0 ${PREFIX}/leapsecs.txt
+ ${PREFIX}/convert-leapsecs
+}
+
+s6-echo "} ;\nuint64 const *const leapsecs_table = leapsecs_table_ ;"