NetBSD-Bugs archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
kern/49207: Add sys/clock.h with generic time macros (derived from clock_subr.h)
>Number: 49207
>Category: kern
>Synopsis: Add sys/clock.h with generic time macros (derived from
>clock_subr.h)
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: kern-bug-people
>State: open
>Class: change-request
>Submitter-Id: net
>Arrival-Date: Tue Sep 16 18:20:00 +0000 2014
>Originator: Kamil Rytarowski
>Release: NetBSD-current 2014-09-10
>Organization:
>Environment:
NetBSD chieftec 6.99.47 NetBSD 6.99.47 (GENERIC) #0: Tue Jul 22 20:20:33 UTC
2014 root@:/build-current/src/sys/arch/amd64/compile/obj/GENERIC amd64
>Description:
Add new file sys/clock.h.
This file is derived from dev/clock_subr.h and contains entirely macros.
Currently kernel exports no Machine Independent file with such content. These
macros are so redefined in many (usually MD) places.
There is similar file for user-space: /usr/include/tzfile.h
With this patch try very hard to:
- avoid name-clash with tzfile.h
- 100% compatibility with clock_subr.h.
FreeBSD exports similar file with the same name based on clock_subr.h from
NetBSD, OpenBSD exports the similar content as sys/time.h (merged from
clock_subr.h).
Discussion at
http://mail-index.netbsd.org/tech-kern/2014/09/15/msg017657.html
diff --git a/dev/clock_subr.h b/dev/clock_subr.h
index 74be860..2492725 100644
--- a/dev/clock_subr.h
+++ b/dev/clock_subr.h
@@ -32,6 +32,8 @@
#ifndef _DEV_CLOCK_SUBR_H_
#define _DEV_CLOCK_SUBR_H_
+#include <sys/clock.h>
+
/*
* "POSIX time" to/from "YY/MM/DD/hh/mm/ss"
*/
@@ -54,13 +56,6 @@ int clock_secs_to_ymdhms(time_t, struct clock_ymdhms *);
#define FROMBCD(x) bcdtobin((x))
#define TOBCD(x) bintobcd((x))
-/* Some handy constants. */
-#define SECDAY (24 * 60 * 60)
-#define SECYR (SECDAY * 365)
-
-/* Traditional POSIX base year */
-#define POSIX_BASE_YEAR 1970
-
/*
* Interface to time-of-day clock devices.
*
diff --git a/sys/Makefile b/sys/Makefile
index 06f7d7e..c8c9ee4 100644
--- a/sys/Makefile
+++ b/sys/Makefile
@@ -7,7 +7,7 @@ INCSDIR= /usr/include/sys
INCS= acct.h agpio.h aio.h ansi.h aout_mids.h ataio.h atomic.h audioio.h \
bitops.h bootblock.h bswap.h buf.h \
callback.h callout.h cdbr.h cdefs.h cdefs_aout.h \
- cdefs_elf.h cdio.h chio.h clockctl.h \
+ cdefs_elf.h cdio.h chio.h clock.h clockctl.h \
common_ansi.h common_int_const.h common_int_fmtio.h \
common_int_limits.h common_int_mwgwtypes.h common_int_types.h \
common_limits.h common_wchar_limits.h \
diff --git a/sys/clock.h b/sys/clock.h
new file mode 100644
index 0000000..fb7d18c
--- /dev/null
+++ b/sys/clock.h
@@ -0,0 +1,48 @@
+/* $NetBSD: $ */
+
+/*-
+ * Copyright (c) 2014 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Gordon W. Ross
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef _SYS_CLOCK_H_
+#define _SYS_CLOCK_H_
+
+#define IS_LEAP_YEAR(year) ((((year) % 4) == 0 && ((year) % 100) != 0) ||
((year%400)) == 0)
+
+#define SECMIN (60L)
+#define SECHOUR (60L * 60L)
+#define SECDAY (24L * 60L * 60L)
+#define DAYSYR(year) (IS_LEAP_YEAR(year) ? 366L : 365L)
+#define SECYR (SECDAY * 365L)
+#define SECLYR (SECDAY * 366L)
+#define SECYEAR(year) (DAYSYR(year) * SECDAY)
+
+/* Traditional POSIX base year */
+#define POSIX_BASE_YEAR 1970
+
+#endif /* _SYS_CLOCK_H_ */
>How-To-Repeat:
N/A
>Fix:
N/A
Home |
Main Index |
Thread Index |
Old Index