summaryrefslogtreecommitdiffstats
path: root/lib/libc/stdtime
diff options
context:
space:
mode:
authordillon <dillon@FreeBSD.org>2001-10-28 19:54:49 +0000
committerdillon <dillon@FreeBSD.org>2001-10-28 19:54:49 +0000
commit5b521f3c4f8da9d35e865fb9daa7a51e4fa00adb (patch)
tree4543d34cc7f31cf4431e62f7bbedbaf0179e4947 /lib/libc/stdtime
parentff38fb0e7374ef63944abf0515667857eaa6d61d (diff)
downloadFreeBSD-src-5b521f3c4f8da9d35e865fb9daa7a51e4fa00adb.zip
FreeBSD-src-5b521f3c4f8da9d35e865fb9daa7a51e4fa00adb.tar.gz
Add routines to convert time_t to/from fixed-bit fields. These routines
serve two purposes: (1) so we can maintain backwards compatibility with protocols (rwhod, dump, etc...) that either assume time_t is 32 bits or assume sizeof(time_t) == sizeof(int), or make other similar assumptions. (2) To tag such routines (by the presence of these calls) for future cleanup/extension work. The 32->64 routine, time32_to_time() (when time_t is 64 bits, that is), is defined specifically to implement temporal locality to properly set the msb bits of a 64 bit time_t quantity, using the 50 year rule. The locality code has not been implemented yet (and doesn't need to be for a while), but that is the intent. This will allow us to maintain backwards protocol compatibility past 2038. These routines are intended to be platform and time_t agnostic. MFC after: 1 week
Diffstat (limited to 'lib/libc/stdtime')
-rw-r--r--lib/libc/stdtime/Makefile.inc3
-rw-r--r--lib/libc/stdtime/time32.c60
2 files changed, 62 insertions, 1 deletions
diff --git a/lib/libc/stdtime/Makefile.inc b/lib/libc/stdtime/Makefile.inc
index 36f909f..f9abc71 100644
--- a/lib/libc/stdtime/Makefile.inc
+++ b/lib/libc/stdtime/Makefile.inc
@@ -3,7 +3,8 @@
.PATH: ${.CURDIR}/../libc/stdtime ${.CURDIR}/../locale
-SRCS+= asctime.c difftime.c localtime.c strftime.c strptime.c timelocal.c
+SRCS+= asctime.c difftime.c localtime.c strftime.c strptime.c timelocal.c \
+ time32.c
.if ${LIB} == "c"
MAN+= ctime.3 strftime.3 strptime.3 time2posix.3
diff --git a/lib/libc/stdtime/time32.c b/lib/libc/stdtime/time32.c
new file mode 100644
index 0000000..4886f7c
--- /dev/null
+++ b/lib/libc/stdtime/time32.c
@@ -0,0 +1,60 @@
+/*-
+ * Copyright (c) 2001 FreeBSD Inc.
+ * All rights reserved.
+ *
+ * These routines are for converting time_t to fixed-bit representations
+ * for use in protocols or storage. When converting time to a larger
+ * representation of time_t these routines are expected to assume temporal
+ * locality and use the 50-year rule to properly set the msb bits. XXX
+ *
+ * Redistribution and use under the terms of the COPYRIGHT file at the
+ * base of the source tree.
+ *
+ * $FreeBSD$
+ */
+
+#include <sys/types.h>
+#include <sys/time.h>
+
+/*
+ * Convert a 32 bit representation of time_t into time_t. XXX needs to
+ * implement the 50-year rule to handle post-2038 conversions.
+ */
+time_t
+time32_to_time(__int32_t t32)
+{
+ return((time_t)t32);
+}
+
+/*
+ * Convert time_t to a 32 bit representation. If time_t is 64 bits we can
+ * simply chop it down. The resulting 32 bit representation can be
+ * converted back to a temporally local 64 bit time_t using time32_to_time.
+ */
+__int32_t
+time_to_time32(time_t t)
+{
+ return((__int32_t)t);
+}
+
+/*
+ * Convert a 64 bit representation of time_t into time_t. If time_t is
+ * represented as 32 bits we can simply chop it and not support times
+ * past 2038.
+ */
+time_t
+time64_to_time(__int64_t t64)
+{
+ return((time_t)t64);
+}
+
+/*
+ * Convert time_t to a 64 bit representation. If time_t is represented
+ * as 32 bits we simply sign-extend and do not support times past 2038.
+ */
+__int64_t
+time_to_time64(time_t t)
+{
+ return((__int64_t)t);
+}
+
OpenPOWER on IntegriCloud