Commit 5b4761003cd93a685745356815424082f11a9804

Con Kolivas 2012-02-09T21:54:23

Move from the thread safe localtime_r to regular localtime which is the only one supported on newer pthread libraries on mingw32 to make it compile with the newer ming. Thread safety is of no importance where localtime is used in this code.

diff --git a/cgminer.c b/cgminer.c
index cd79a19..fa89cff 100644
--- a/cgminer.c
+++ b/cgminer.c
@@ -238,16 +238,16 @@ static bool time_before(struct tm *tm1, struct tm *tm2)
 static bool should_run(void)
 {
 	struct timeval tv;
-	struct tm tm;
+	struct tm *tm;
 
 	if (!schedstart.enable && !schedstop.enable)
 		return true;
 
 	gettimeofday(&tv, NULL);
-	localtime_r(&tv.tv_sec, &tm);
+	tm = localtime(&tv.tv_sec);
 	if (schedstart.enable) {
 		if (!schedstop.enable) {
-			if (time_before(&tm, &schedstart.tm))
+			if (time_before(tm, &schedstart.tm))
 				return false;
 
 			/* This is a once off event with no stop time set */
@@ -255,46 +255,46 @@ static bool should_run(void)
 			return true;
 		}
 		if (time_before(&schedstart.tm, &schedstop.tm)) {
-			if (time_before(&tm, &schedstop.tm) && !time_before(&tm, &schedstart.tm))
+			if (time_before(tm, &schedstop.tm) && !time_before(tm, &schedstart.tm))
 				return true;
 			return false;
 		} /* Times are reversed */
-		if (time_before(&tm, &schedstart.tm)) {
-			if (time_before(&tm, &schedstop.tm))
+		if (time_before(tm, &schedstart.tm)) {
+			if (time_before(tm, &schedstop.tm))
 				return true;
 			return false;
 		}
 		return true;
 	}
 	/* only schedstop.enable == true */
-	if (!time_before(&tm, &schedstop.tm))
+	if (!time_before(tm, &schedstop.tm))
 		return false;
 	return true;
 }
 
 void get_datestamp(char *f, struct timeval *tv)
 {
-	struct tm tm;
+	struct tm *tm;
 
-	localtime_r(&tv->tv_sec, &tm);
+	tm = localtime(&tv->tv_sec);
 	sprintf(f, "[%d-%02d-%02d %02d:%02d:%02d]",
-		tm.tm_year + 1900,
-		tm.tm_mon + 1,
-		tm.tm_mday,
-		tm.tm_hour,
-		tm.tm_min,
-		tm.tm_sec);
+		tm->tm_year + 1900,
+		tm->tm_mon + 1,
+		tm->tm_mday,
+		tm->tm_hour,
+		tm->tm_min,
+		tm->tm_sec);
 }
 
 void get_timestamp(char *f, struct timeval *tv)
 {
-	struct tm tm;
+	struct tm *tm;
 
-	localtime_r(&tv->tv_sec, &tm);
+	tm = localtime(&tv->tv_sec);
 	sprintf(f, "[%02d:%02d:%02d]",
-		tm.tm_hour,
-		tm.tm_min,
-		tm.tm_sec);
+		tm->tm_hour,
+		tm->tm_min,
+		tm->tm_sec);
 }
 
 static void applog_and_exit(const char *fmt, ...)
diff --git a/util.c b/util.c
index 9a8f08e..563a4d7 100644
--- a/util.c
+++ b/util.c
@@ -79,21 +79,21 @@ void vapplog(int prio, const char *fmt, va_list ap)
 		char *f;
 		int len;
 		struct timeval tv = { };
-		struct tm tm;
+		struct tm *tm;
 
 		gettimeofday(&tv, NULL);
 
-		localtime_r(&tv.tv_sec, &tm);
+		tm = localtime(&tv.tv_sec);
 
 		len = 40 + strlen(fmt) + 22;
 		f = alloca(len);
 		sprintf(f, "[%d-%02d-%02d %02d:%02d:%02d] %s\n",
-			tm.tm_year + 1900,
-			tm.tm_mon + 1,
-			tm.tm_mday,
-			tm.tm_hour,
-			tm.tm_min,
-			tm.tm_sec,
+			tm->tm_year + 1900,
+			tm->tm_mon + 1,
+			tm->tm_mday,
+			tm->tm_hour,
+			tm->tm_min,
+			tm->tm_sec,
 			fmt);
 		/* Only output to stderr if it's not going to the screen as well */
 		if (!isatty(fileno((FILE *)stderr))) {