aboutsummaryrefslogtreecommitdiffstats
path: root/wsutil
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2020-01-21 14:26:38 -0800
committerGuy Harris <guy@alum.mit.edu>2020-01-21 23:37:05 +0000
commita152e041fa893ba672dcb1337c596ec15fdb0c0d (patch)
tree17debde7ec0104d70d12e67bb4e5d8764ef076d1 /wsutil
parentd44c5e45cbb5e9ece96cab6a62793dd24ec52b7d (diff)
Put various epoch time deltas into wsutil/epochs.h.
There are some deltas between the UN*X epoch and other epochs that are used in a number of places; put them into a header. Change-Id: Ia2d9d69b9d91352d730d97d9e4897518635b4861 Reviewed-on: https://code.wireshark.org/review/35895 Petri-Dish: Guy Harris <guy@alum.mit.edu> Tested-by: Petri Dish Buildbot Reviewed-by: Guy Harris <guy@alum.mit.edu>
Diffstat (limited to 'wsutil')
-rw-r--r--wsutil/CMakeLists.txt1
-rw-r--r--wsutil/epochs.h57
-rw-r--r--wsutil/nstime.c32
-rw-r--r--wsutil/time_util.c4
4 files changed, 66 insertions, 28 deletions
diff --git a/wsutil/CMakeLists.txt b/wsutil/CMakeLists.txt
index c7d017cf7b..1e1e453e2b 100644
--- a/wsutil/CMakeLists.txt
+++ b/wsutil/CMakeLists.txt
@@ -34,6 +34,7 @@ set(WSUTIL_PUBLIC_HEADERS
crc32.h
curve25519.h
eax.h
+ epochs.h
filesystem.h
frequency-utils.h
g711.h
diff --git a/wsutil/epochs.h b/wsutil/epochs.h
new file mode 100644
index 0000000000..c6f28cea6a
--- /dev/null
+++ b/wsutil/epochs.h
@@ -0,0 +1,57 @@
+/* epochs.h
+ * Definitions of epoch values for various absolute time types.
+ *
+ * Wireshark - Network traffic analyzer
+ * By Gerald Combs <gerald@wireshark.org>
+ * Copyright 2006 Gerald Combs
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+
+#ifndef __EPOCHS_H__
+#define __EPOCHS_H__
+
+#include <glib.h>
+
+/*
+ * Deltas between the epochs for various non-UN*X time stamp formats and
+ * the January 1, 1970, 00:00:00 (proleptic?) UTC epoch for the UN*X time
+ * stamp format.
+ */
+
+/*
+ * 1900-01-01 00:00:00 (proleptic?) UTC.
+ * Used by a number of time formats.
+ */
+#define EPOCH_DELTA_1900_01_01_00_00_00_UTC 2208988800U
+
+/*
+ * 1904-01-01 00:00:00 (proleptic?) UTC.
+ * Used in the classic Mac OS, and by formats, such as MPEG-4 Part 14 (MP4),
+ * which is based on Apple's QuickTime format.
+ */
+#define EPOCH_DELTA_1904_01_01_00_00_00_UTC 2082844800U
+
+/*
+ * 1601-01-01 (proleptic Gregorian) 00:00:00 (proleptic?) UTC.
+ * The Windows NT epoch, used in a number of places.
+ *
+ * This is
+ *
+ * 369*365.25*24*60*60-(3*24*60*60+6*60*60)
+ *
+ * 1970-1601 is 369; 365.25 is the average length of a year in days,
+ * including leap years.
+ *
+ * 3 days are subtracted because 1700, 1800, and 1900 were not leap
+ * years, as, while they're all evenly divisible by 4, they're also
+ * evently divisible by 100, but not evently divisible by 400, so
+ * we need to compensate for using the average length of a year in
+ * days, which assumes a leap year every 4 years, *including* every
+ * 100 years.
+ *
+ * I'm not sure what the extra 6 hours are that are being subtracted.
+ */
+#define EPOCH_DELTA_1601_01_01_00_00_00_UTC G_GUINT64_CONSTANT(11644473600)
+
+#endif /* __EPOCHS_H__ */
diff --git a/wsutil/nstime.c b/wsutil/nstime.c
index 456530a5e3..2b2020d340 100644
--- a/wsutil/nstime.c
+++ b/wsutil/nstime.c
@@ -12,6 +12,7 @@
#include <glib.h>
#include "nstime.h"
+#include "epochs.h"
/* this is #defined so that we can clearly see that we have the right number of
zeros, rather than as a guard against the number of nanoseconds in a second
@@ -182,29 +183,6 @@ double nstime_to_sec(const nstime_t *nstime)
* Copyright (C) Andrew Tridgell 1992-1998
*/
-/*
- * Number of seconds between the UN*X epoch (January 1, 1970, 00:00:00 GMT)
- * and the Windows NT epoch (January 1, 1601 in the proleptic Gregorian
- * calendar, 00:00:00 "GMT")
- *
- * This is
- *
- * 369*365.25*24*60*60-(3*24*60*60+6*60*60)
- *
- * 1970-1601 is 369; 365.25 is the average length of a year in days,
- * including leap years.
- *
- * 3 days are subtracted because 1700, 1800, and 1900 were not leap
- * years, as, while they're all evenly divisible by 4, they're also
- * evently divisible by 100, but not evently divisible by 400, so
- * we need to compensate for using the average length of a year in
- * days, which assumes a leap year every 4 years, *including* every
- * 100 years.
- *
- * I'm not sure what the extra 6 hours are that are being subtracted.
- */
-#define TIME_FIXUP_CONSTANT G_GUINT64_CONSTANT(11644473600)
-
#ifndef TIME_T_MIN
#define TIME_T_MIN ((time_t) ((time_t)0 < (time_t) -1 ? (time_t) 0 \
: (time_t) (~0ULL << (sizeof (time_t) * CHAR_BIT - 1))))
@@ -223,11 +201,11 @@ common_filetime_to_nstime(nstime_t *nstime, guint64 ftsecs, int nsecs)
* ftsecs's value should fit in a 64-bit signed variable, as
* ftsecs is derived from a 64-bit fractions-of-a-second value,
* and is far from the maximum 64-bit signed value, and
- * TIME_FIXUP_CONSTANT is also far from the maximum 64-bit
- * signed value, so the difference between them should also
- * fit in a 64-bit signed value.
+ * EPOCH_DELTA_1601_01_01_00_00_00_UTC is also far from the
+ * maximum 64-bit signed value, so the difference between them
+ * should also fit in a 64-bit signed value.
*/
- secs = (gint64)ftsecs - TIME_FIXUP_CONSTANT;
+ secs = (gint64)ftsecs - EPOCH_DELTA_1601_01_01_00_00_00_UTC;
if (!(TIME_T_MIN <= secs && secs <= TIME_T_MAX)) {
/* The result won't fit in a time_t */
diff --git a/wsutil/time_util.c b/wsutil/time_util.c
index 32cbc81a85..98df723a9b 100644
--- a/wsutil/time_util.c
+++ b/wsutil/time_util.c
@@ -12,6 +12,8 @@
#include <glib.h>
+#include <wsutil/epochs.h>
+
#include "time_util.h"
#ifndef _WIN32
@@ -147,7 +149,7 @@ create_timestamp(void) {
* Subtract difference, in microseconds, between January 1, 1601
* 00:00:00 UTC and January 1, 1970, 00:00:00 UTC.
*/
- timestamp -= G_GUINT64_CONSTANT(11644473600000000);
+ timestamp -= EPOCH_DELTA_1601_01_01_00_00_00_UTC*1000000;
#else
/*
* Current time, represented as seconds and microseconds since