]> git.ipfire.org Git - thirdparty/libbsd.git/commitdiff
Add timeconv module from FreeBSD
authorGuillem Jover <guillem@hadrons.org>
Fri, 11 Oct 2013 03:43:42 +0000 (05:43 +0200)
committerGuillem Jover <guillem@hadrons.org>
Mon, 21 Oct 2013 03:48:30 +0000 (05:48 +0200)
Inline license information from FreeBSD root dir COPYRIGHT file.

COPYING
include/Makefile.am
include/bsd/timeconv.h [new file with mode: 0644]
src/Makefile.am
src/libbsd.map
src/timeconv.c [new file with mode: 0644]

diff --git a/COPYING b/COPYING
index 285ed8f9803ede0f568d1d9bd7d1d7d0dea2758f..2a40164bff5428749b3531036dff7c0ebecff5dc 100644 (file)
--- a/COPYING
+++ b/COPYING
@@ -118,6 +118,12 @@ The rest of the licenses apply to code and/or man pages.
     Some code is derived from software contributed to Berkeley by
     Chris Torek.
 
+    © UNIX System Laboratories, Inc.
+    All or some portions of this file are derived from material licensed
+    to the University of California by American Telephone and Telegraph
+    Co. or Unix System Laboratories, Inc. and are reproduced herein with
+    the permission of UNIX System Laboratories, Inc.
+
     Redistribution and use in source and binary forms, with or without
     modification, are permitted provided that the following conditions
     are met:
@@ -243,6 +249,9 @@ The rest of the licenses apply to code and/or man pages.
     Copyright © 2001 Dima Dorfman.
     All rights reserved.
 
+    Copyright © 2001 FreeBSD Inc.
+    All rights reserved.
+
     Copyright © 2002 Thomas Moestl <tmm@FreeBSD.org>
     All rights reserved.
 
index 9b8e4c390fec90b33e07058962a26edb4dcae270..d8843c1fe0216ee7d50ccdd221af53ca0f02a338 100644 (file)
@@ -19,6 +19,7 @@ nobase_include_HEADERS = \
        bsd/stdio.h \
        bsd/stdlib.h \
        bsd/string.h \
+       bsd/timeconv.h \
        bsd/unistd.h \
        bsd/vis.h \
        bsd/wchar.h \
diff --git a/include/bsd/timeconv.h b/include/bsd/timeconv.h
new file mode 100644 (file)
index 0000000..29e0988
--- /dev/null
@@ -0,0 +1,57 @@
+/*
+ * Copyright (c) 1989, 1993
+ *     The Regents of the University of California.  All rights reserved.
+ * (c) UNIX System Laboratories, Inc.
+ * All or some portions of this file are derived from material licensed
+ * to the University of California by American Telephone and Telegraph
+ * Co. or Unix System Laboratories, Inc. and are reproduced herein with
+ * the permission of UNIX System Laboratories, Inc.
+ *
+ * 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.
+ * 3. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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.
+ *
+ *     @(#)time.h      8.3 (Berkeley) 1/21/94
+ */
+
+/*
+ * $FreeBSD$
+ */
+
+#ifndef _TIMECONV_H_
+#define _TIMECONV_H_
+
+#include <sys/cdefs.h>
+#include <stdint.h>
+#include <time.h>
+
+time_t _time32_to_time(int32_t t32);
+int32_t _time_to_time32(time_t t);
+time_t _time64_to_time(int64_t t64);
+int64_t _time_to_time64(time_t t);
+long _time_to_long(time_t t);
+time_t _long_to_time(long tlong);
+int _time_to_int(time_t t);
+time_t _int_to_time(int tint);
+
+#endif /* _TIMECONV_H_ */
index 5573520713c572633faafa477226b85e8b1e888c..c9a4df0f346e487b09e8cb22ed40277e4c09f055 100644 (file)
@@ -73,6 +73,7 @@ libbsd_la_SOURCES = \
        strmode.c \
        strnstr.c \
        strtonum.c \
+       timeconv.c \
        unvis.c \
        vis.c \
        wcslcat.c \
index de1b2902a75e8da8daeffc2f672afc937d1b5427..4d483df3cd61d01f018659c87a00fb254e976460 100644 (file)
@@ -113,4 +113,13 @@ LIBBSD_0.6 {
 
 LIBBSD_0.7 {
     funopen;
+
+    _time32_to_time;
+    _time_to_time32;
+    _time64_to_time;
+    _time_to_time64;
+    _time_to_long;
+    _long_to_time;
+    _time_to_int;
+    _int_to_time;
 } LIBBSD_0.6;
diff --git a/src/timeconv.c b/src/timeconv.c
new file mode 100644 (file)
index 0000000..7ee5388
--- /dev/null
@@ -0,0 +1,119 @@
+/*-
+ * Copyright (c) 2001 FreeBSD Inc.
+ * All rights reserved.
+ *
+ * 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 AUTHOR 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 AUTHOR 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.
+ *
+ * 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
+ *
+ */
+
+#include <sys/cdefs.h>
+__FBSDID("$FreeBSD$");
+
+#include <sys/types.h>
+#include <timeconv.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);
+}
+
+/*
+ * Convert to/from 'long'.  Depending on the sizeof(long) this may or
+ * may not require using the 50-year rule.
+ */
+long
+_time_to_long(time_t t)
+{
+    if (sizeof(long) == sizeof(int64_t))
+       return(_time_to_time64(t));
+    return((long)t);
+}
+
+time_t
+_long_to_time(long tlong)
+{
+    if (sizeof(long) == sizeof(int32_t))
+       return(_time32_to_time(tlong));
+    return((time_t)tlong);
+}
+
+/*
+ * Convert to/from 'int'.  Depending on the sizeof(int) this may or
+ * may not require using the 50-year rule.
+ */
+int
+_time_to_int(time_t t)
+{
+    if (sizeof(int) == sizeof(int64_t))
+       return(_time_to_time64(t));
+    return((int)t);
+}
+
+time_t
+_int_to_time(int tint)
+{
+    if (sizeof(int) == sizeof(int32_t))
+       return(_time32_to_time(tint));
+    return((time_t)tint);
+}