From da8b7dcb64bb3f022c28d5dd721850bcdb3f04e2 Mon Sep 17 00:00:00 2001
From: rswindell <>
Date: Sat, 23 Feb 2008 22:18:37 +0000
Subject: [PATCH] Move checktime() implementation to datewrap.* and always call
 checktime() in xptime.

---
 src/xpdev/datewrap.c | 13 +++++++++++++
 src/xpdev/datewrap.h |  3 +++
 src/xpdev/xptime.c   | 20 +++-----------------
 3 files changed, 19 insertions(+), 17 deletions(-)

diff --git a/src/xpdev/datewrap.c b/src/xpdev/datewrap.c
index 5b6a3ee970..adf1cfd51b 100644
--- a/src/xpdev/datewrap.c
+++ b/src/xpdev/datewrap.c
@@ -39,6 +39,19 @@
 #include "genwrap.h"
 #include "datewrap.h"
 
+/* Return difference (in seconds) in time() result from standard */
+time_t checktime(void)
+{
+	time_t		t=0x2D24BD00L;	/* Correct time_t value on Jan-1-1994 */
+	struct tm	gmt;
+	struct tm	tm;
+
+	memset(&tm,0,sizeof(tm));
+	tm.tm_year=94;
+	tm.tm_mday=1;
+	return mktime(&tm) - mktime(gmtime_r(&t,&gmt));
+}
+
 /* Compensates for struct tm "weirdness" */
 time_t sane_mktime(struct tm* tm)
 {
diff --git a/src/xpdev/datewrap.h b/src/xpdev/datewrap.h
index 61ad446a3b..f7dc89b5d1 100644
--- a/src/xpdev/datewrap.h
+++ b/src/xpdev/datewrap.h
@@ -44,6 +44,9 @@
 extern "C" {
 #endif
 
+/* Return difference (in seconds) in time() result from standard (0 on success) */
+time_t checktime(void);
+
 /* Implementation of mktime() that handles common tm element conversions for you */
 time_t sane_mktime(struct tm* tm);
 
diff --git a/src/xpdev/xptime.c b/src/xpdev/xptime.c
index ec25f16ef3..9b7057236e 100644
--- a/src/xpdev/xptime.c
+++ b/src/xpdev/xptime.c
@@ -13,16 +13,6 @@
 #include "datewrap.h"
 #include "xpdatetime.h"
 
-time_t checktime()
-{
-	struct tm tm;
-
-	memset(&tm,0,sizeof(tm));
-	tm.tm_year=94;
-	tm.tm_mday=1;
-	return(mktime(&tm)^0x2D24BD00L);
-}
-
 int main(int argc, char **argv)
 {
 	char			str[256];
@@ -39,13 +29,6 @@ int main(int argc, char **argv)
 
 	printf("Rev %s Built " __DATE__ " " __TIME__ " with %s\n\n", revision, str);
 
-#if 0
-
-	if((t=checktime())!=0L) {
-		printf("Time problem (%08lX)\n",t);
-		exit(1); }
-#endif
-
 	if(argc<2)
 		printf("usage: xptime [-z] <date_str || time_t>\n\n");
 
@@ -56,6 +39,9 @@ int main(int argc, char **argv)
 	}
 	tzset();
 
+	if((t=checktime())!=0L)
+		printf("!time() result diverges from standard by: %ld seconds\n\n",t);
+
 	printf("Current timezone: %d\n", xpTimeZone_local());
 	printf("\n");
 
-- 
GitLab