1 /*-
2 * Copyright (c) 2004, 2005, 2007, 2011, 2012
3 * Thorsten Glaser <tg@mirbsd.org>
4 *
5 * Provided that these terms and disclaimer and all copyright notices
6 * are retained or reproduced in an accompanying document, permission
7 * is granted to deal in this work without restriction, including un-
8 * limited rights to use, publicly perform, distribute, sell, modify,
9 * merge, give away, or sublicence.
10 *
11 * This work is provided "AS IS" and WITHOUT WARRANTY of any kind, to
12 * the utmost extent permitted by applicable law, neither express nor
13 * implied; without malicious intent or gross negligence. In no event
14 * may a licensor, author or contributor be held liable for indirect,
15 * direct, other damage, loss, or other issues arising in any way out
16 * of dealing in the work, even if advised of the possibility of such
17 * damage or existence of a defect, except proven that it results out
18 * of said person's immediate fault when using the work as intended.
19 *-
20 * Generate a dump of what leap seconds userspace currently knows of,
21 * for use within an environment where tzdata is not available.
22 */
23
24 #include <err.h>
25 #include <stdio.h>
26 #include <time.h>
27
28 __RCSID("$MirOS: src/sys/conf/make_leaps.c,v 1.3 2012/09/07 20:06:40 tg Exp $");
29
30 static const char preamble[] =
31 "/* AUTOMATICALLY GENERATED - DO NOT EDIT! */\n"
32 "\n"
33 "#include <sys/time.h>\n"
34 "\n"
35 "__RCSID(\"From: $MirOS: src/sys/conf/make_leaps.c,v 1.3 2012/09/07 20:06:40 tg Exp $\");\n"
36 "\n"
37 "static time_t _leaps_tt[] = {\n";
38
39 static const char epilogue[] =
40 " /* spare for config(8) */\n"
41 " 0,\n"
42 " 0,\n"
43 " 0,\n"
44 " 0,\n"
45 " 0,\n"
46 " 0,\n"
47 " /* last one must be 0 */\n"
48 " 0,\n"
49 " /* past last one must be -1 */\n"
50 " (time_t)-1\n"
51 "};\n"
52 "\n"
53 "const time_t *\n"
54 "mirtime_getleaps(void)\n"
55 "{\n"
56 " return (_leaps_tt);\n"
57 "}\n";
58
59 int
main(void)60 main(void)
61 {
62 const time_t *lp;
63
64 lp = mirtime_getleaps();
65
66 fputs(preamble, stdout);
67 while (*lp)
68 if (sizeof(time_t) == 4)
69 printf("\t0x%08XL,\n", (uint32_t)*lp++);
70 else
71 printf("\t0x%016llXLL,\n", (uint64_t)*lp++);
72 fputs(epilogue, stdout);
73
74 return (0);
75 }
76