- Add an entry for iwl(4)
[dragonfly.git] / usr.sbin / rdate / ntpleaps.h
blob9971c407d231a2b7c67b13bc2dc4a393b1016502
1 /* $OpenBSD: src/usr.sbin/rdate/ntpleaps.h,v 1.3 2004/05/05 20:29:54 jakob Exp $ */
2 /* $DragonFly: src/usr.sbin/rdate/ntpleaps.h,v 1.1 2004/12/01 15:04:43 joerg Exp $ */
4 /*
5 * Copyright (c) 2002 Thorsten Glaser. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
11 * - Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * - Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
24 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
28 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
33 /* Leap second support for SNTP clients
34 * This header file and its corresponding C file provide generic
35 * ability for NTP or SNTP clients to correctly handle leap seconds
36 * by reading them from an always existing file and subtracting the
37 * leap seconds from the NTP return value before setting the posix
38 * clock. This is fairly portable between operating systems and may
39 * be used for patching other ntp clients, too. The tzfile used is:
40 * /usr/share/zoneinfo/right/UTC which is available on any unix-like
41 * platform with the Olson tz library, which is necessary to get real
42 * leap second zoneinfo files and userland support anyways.
45 #ifndef _NTPLEAPS_H
46 #define _NTPLEAPS_H
48 /* Offset between struct timeval.tv_sec and a tai64_t */
49 #define NTPLEAPS_OFFSET (4611686018427387914ULL)
51 /* Hide this ugly value from programmes */
52 #define SEC_TO_TAI64(s) (NTPLEAPS_OFFSET + (u_int64_t)(s))
53 #define TAI64_TO_SEC(t) ((t) - NTPLEAPS_OFFSET)
55 /* Initializes the leap second table. Does not need to be called
56 * before usage of the subtract funtion, but calls ntpleaps_read.
57 * returns 0 on success, -1 on error (displays a warning on stderr)
59 int ntpleaps_init(void);
61 /* Re-reads the leap second table, thus consuming quite much time.
62 * Ought to be called from within daemons at least once a month to
63 * ensure the in-memory table is always up-to-date.
64 * returns 0 on success, -1 on error (leap seconds will not be available)
66 int ntpleaps_read(void);
68 /* Subtracts leap seconds from the given value (converts NTP time
69 * to posix clock tick time.
70 * returns 0 on success, -1 on error (time is unchanged), 1 on leap second
72 int ntpleaps_sub(u_int64_t *);
74 #endif