changeset 6584:4fb613eb8ce9 HEAD

utc_mktime() was broken with 32bit time_t. Also don't try to optimize away the seconds, it doesn't really help and it makes the lowest time_t values unusable.
author Timo Sirainen <tss@iki.fi>
date Sun, 21 Oct 2007 04:49:45 +0300
parents 104a8929ef7c
children a9dfe05dfadd
files src/lib/utc-mktime.c
diffstat 1 files changed, 4 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib/utc-mktime.c	Sun Oct 21 03:33:21 2007 +0300
+++ b/src/lib/utc-mktime.c	Sun Oct 21 04:49:45 2007 +0300
@@ -23,8 +23,7 @@
 time_t utc_mktime(const struct tm *tm)
 {
 	const struct tm *try_tm;
-	struct tm nosec_tm;
-	time_t t;
+	int t;
 	int bits, dir;
 
 	/* we'll do a binary search across the entire valid time_t range.
@@ -33,21 +32,14 @@
 	   values, -1 is returned. */
 #ifdef TIME_T_SIGNED
 	t = 0;
-	bits = TIME_T_MAX_BITS - 1;
 #else
 	t = 1 << (TIME_T_MAX_BITS - 1);
-	bits = TIME_T_MAX_BITS - 2;
 #endif
-
-	/* we can ignore seconds in checks and add them back when returning */
-	nosec_tm = *tm;
-	nosec_tm.tm_sec = 0;
-
-	for (;; bits--) {
+	for (bits = TIME_T_MAX_BITS - 2;; bits--) {
 		try_tm = gmtime(&t);
-		dir = tm_cmp(&nosec_tm, try_tm);
+		dir = tm_cmp(tm, try_tm);
 		if (dir == 0)
-			return t + tm->tm_sec;
+			return t;
 		if (bits < 0)
 			break;