summaryrefslogtreecommitdiff
path: root/tools/convert-leapsecs.c
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/convert-leapsecs.c
parent2e0421fc58922697f2bb51c428599fbd44055556 (diff)
downloadskalibs-805729e206b7586c57483aa0f4a90f7e0e2c9661.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/convert-leapsecs.c')
-rw-r--r--tools/convert-leapsecs.c53
1 files changed, 53 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 ;
+}