[Box Backup-commit] COMMIT r1565 - box/chris/merge/lib/common

boxbackup-dev@fluffy.co.uk boxbackup-dev@fluffy.co.uk
Sun, 22 Apr 2007 16:45:06 +0100


Author: chris
Date: 2007-04-22 16:45:05 +0100 (Sun, 22 Apr 2007)
New Revision: 1565

Modified:
   box/chris/merge/lib/common/Logging.cpp
Log:
Compile fix for Win32, where no localtime_r is available and localtime
is thread safe. (refs #3)


Modified: box/chris/merge/lib/common/Logging.cpp
===================================================================
--- box/chris/merge/lib/common/Logging.cpp	2007-04-22 15:43:23 UTC (rev 1564)
+++ box/chris/merge/lib/common/Logging.cpp	2007-04-22 15:45:05 UTC (rev 1565)
@@ -210,7 +210,7 @@
 
 	if (sShowTime)
 	{
-		struct tm time_now;
+		struct tm time_now, *tm_ptr = &time_now;
 		time_t time_t_now = time(NULL);
 
 		if (time_t_now == ((time_t)-1))
@@ -218,13 +218,17 @@
 			msg += strerror(errno);
 			msg += " ";
 		}
-		else if (localtime_r(&time_t_now, &time_now) != NULL)
+		#ifdef WIN32
+			else if ((tm_ptr = localtime(&time_t_now)) != NULL)
+		#else
+			else if (localtime_r(&time_t_now, &time_now) != NULL)
+		#endif
 		{
 			std::ostringstream buf;
 			buf << std::setfill('0') <<
-				std::setw(2) << time_now.tm_hour << ":" << 
-				std::setw(2) << time_now.tm_min  << ":" <<
-				std::setw(2) << time_now.tm_sec  << " ";
+				std::setw(2) << tm_ptr->tm_hour << ":" << 
+				std::setw(2) << tm_ptr->tm_min  << ":" <<
+				std::setw(2) << tm_ptr->tm_sec  << " ";
 			msg += buf.str();
 		}
 		else