Make Win32 TimeValue::toString() re-entrant and work with mingw
authorJeff Cohen <jeffc@jolt-lang.org>
Wed, 15 Dec 2004 04:28:44 +0000 (04:28 +0000)
committerJeff Cohen <jeffc@jolt-lang.org>
Wed, 15 Dec 2004 04:28:44 +0000 (04:28 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@18954 91177308-0d34-0410-b5e6-96231b3b80d8

lib/System/Win32/TimeValue.cpp
lib/System/Win32/TimeValue.inc

index f45662948bc106b5cdc7b9afbf12144283f2a869..de8f267089dc2f73f4a98a33e23c6bbc7024671a 100644 (file)
@@ -31,13 +31,17 @@ TimeValue TimeValue::now() {
 }
 
 std::string TimeValue::toString() const {
-  // Alas, asctime is not re-entrant on Windows...
-
+#ifdef __MINGW
+  time_t ourTime = time_t(this->toEpochTime());
+  struct tm *lt = ::localtime(&ourTime);
+#else
   __time64_t ourTime = this->toEpochTime();
-  char* buffer = ::asctime(::_localtime64(&ourTime));
+  struct tm *lt = ::_localtime64(&ourTime);
+#endif
 
-  std::string result(buffer);
-  return result.substr(0,24);
+  char buffer[25];
+  strftime(buffer, 25, "%a %b %d %H:%M:%S %Y", lt);
+  return std::string(buffer);
 }
 
 // vim: sw=2 smartindent smarttab tw=80 autoindent expandtab
index f45662948bc106b5cdc7b9afbf12144283f2a869..de8f267089dc2f73f4a98a33e23c6bbc7024671a 100644 (file)
@@ -31,13 +31,17 @@ TimeValue TimeValue::now() {
 }
 
 std::string TimeValue::toString() const {
-  // Alas, asctime is not re-entrant on Windows...
-
+#ifdef __MINGW
+  time_t ourTime = time_t(this->toEpochTime());
+  struct tm *lt = ::localtime(&ourTime);
+#else
   __time64_t ourTime = this->toEpochTime();
-  char* buffer = ::asctime(::_localtime64(&ourTime));
+  struct tm *lt = ::_localtime64(&ourTime);
+#endif
 
-  std::string result(buffer);
-  return result.substr(0,24);
+  char buffer[25];
+  strftime(buffer, 25, "%a %b %d %H:%M:%S %Y", lt);
+  return std::string(buffer);
 }
 
 // vim: sw=2 smartindent smarttab tw=80 autoindent expandtab