Fix a FIXME about the format and add a test.
authorRafael Espindola <rafael.espindola@gmail.com>
Thu, 11 Jul 2013 15:35:23 +0000 (15:35 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Thu, 11 Jul 2013 15:35:23 +0000 (15:35 +0000)
While at it, use strftime on Unix too and use the thread safe versions
of localtime.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@186090 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Support/Unix/TimeValue.inc
lib/Support/Windows/TimeValue.inc
test/Object/archive-toc.test
tools/llvm-ar/llvm-ar.cpp

index df8558bf8bedaa2f71e69e832e6498fb96e1f945..80532b0b952489c7a4f3b76010c1b8799670ecae 100644 (file)
@@ -22,18 +22,13 @@ namespace llvm {
   using namespace sys;
 
 std::string TimeValue::str() const {
-  char buffer[32];
-
-  time_t ourTime = time_t(this->toEpochTime());
-#ifdef __hpux
-// note that the following line needs -D_REENTRANT on HP-UX to be picked up
-  asctime_r(localtime(&ourTime), buffer);
-#else
-  ::asctime_r(::localtime(&ourTime), buffer);
-#endif
-
-  std::string result(buffer);
-  return result.substr(0,24);
+  time_t OurTime = time_t(this->toEpochTime());
+  struct tm Storage;
+  struct tm *LT = ::localtime_r(&OurTime, &Storage);
+  assert(LT);
+  char Buffer[25];
+  strftime(Buffer, 25, "%b %e %H:%M %Y", LT);
+  return std::string(Buffer);
 }
 
 TimeValue TimeValue::now() {
index 12275526f1c8ca701ae054a70b6d2303b2c262c9..32983be883f3bdaeb7d11fc0ab3de44dab3627dc 100644 (file)
@@ -31,20 +31,15 @@ TimeValue TimeValue::now() {
 }
 
 std::string TimeValue::str() const {
-#ifdef __MINGW32__
-  // This ban may be lifted by either:
-  // (i) a future MinGW version other than 1.0 inherents the __time64_t type, or
-  // (ii) configure tests for either the time_t or __time64_t type.
-  time_t ourTime = time_t(this->toEpochTime());
-  struct tm *lt = ::localtime(&ourTime);
-#else
-  __time64_t ourTime = this->toEpochTime();
-  struct tm *lt = ::_localtime64(&ourTime);
-#endif
-
-  char buffer[25];
-  strftime(buffer, 25, "%a %b %d %H:%M:%S %Y", lt);
-  return std::string(buffer);
+  struct tm LT;
+  __time64_t OurTime = this->toEpochTime();
+  errno_t Error = ::_localtime64_s(&LT, &OurTime);
+  assert(!Error);
+
+  char Buffer[25];
+  // FIXME: the windows version of strftime doesn't support %e
+  strftime(Buffer, 25, "%b %d %H:%M %Y", &LT);
+  return std::string(Buffer);
 }
 
 
index e11dac5d018d29bf072a237d6f48ef240a52945c..f99588d9408c6276016b7d8c8c7f8a44279f3954 100644 (file)
@@ -1,16 +1,31 @@
+REQUIRES: shell
+
+RUN: export TZ=GMT
+
 Test reading an archive created by gnu ar
-RUN: llvm-ar t %p/Inputs/GNU.a | FileCheck %s
+RUN: llvm-ar tv %p/Inputs/GNU.a | FileCheck %s --check-prefix=GNU -strict-whitespace
+
+GNU:      rw-r--r-- 500/500      8 Nov 19 02:57 2004 evenlen
+GNU-NEXT: rw-r--r-- 500/500      7 Nov 19 02:57 2004 oddlen
+GNU-NEXT: rwxr-xr-x 500/500   1465 Nov 19 03:01 2004 very_long_bytecode_file_name.bc
+GNU-NEXT: rw-r--r-- 500/500   2280 Nov 19 03:04 2004 IsNAN.o
+
 
 Test reading an archive createdy by Mac OS X ar
-RUN: llvm-ar t %p/Inputs/MacOSX.a | FileCheck %s
+RUN: llvm-ar tv %p/Inputs/MacOSX.a | FileCheck %s --check-prefix=OSX -strict-whitespace
+
+OSX:      rw-r--r-- 501/501      8 Nov 19 02:57 2004 evenlen
+OSX-NEXT: rw-r--r-- 501/501      8 Nov 19 02:57 2004 oddlen
+OSX-NEXT: rw-r--r-- 502/502   1465 Feb  4 06:59 2010 very_long_bytecode_file_name.bc
+OSX-NEXT: rw-r--r-- 501/501   2280 Nov 19 04:32 2004 IsNAN.o
 
 Test reading an archive created on Solaris by /usr/ccs/bin/ar
-RUN: llvm-ar t %p/Inputs/SVR4.a | FileCheck %s
+RUN: llvm-ar tv %p/Inputs/SVR4.a | FileCheck %s -strict-whitespace
 
 Test reading an archive created on Solaris by /usr/xpg4/bin/ar
-RUN: llvm-ar t %p/Inputs/xpg4.a | FileCheck %s
+RUN: llvm-ar tv %p/Inputs/xpg4.a | FileCheck %s -strict-whitespace
 
-CHECK:      evenlen
-CHECK-NEXT: oddlen
-CHECK-NEXT: very_long_bytecode_file_name.bc
-CHECK-NEXT: IsNAN.o
+CHECK:      rw-r--r-- 1002/102      8 Nov 19 03:24 2004 evenlen
+CHECK-NEXT: rw-r--r-- 1002/102      7 Nov 19 03:24 2004 oddlen
+CHECK-NEXT: rwxr-xr-x 1002/102   1465 Nov 19 03:24 2004 very_long_bytecode_file_name.bc
+CHECK-NEXT: rw-r--r-- 1002/102   2280 Nov 19 03:24 2004 IsNAN.o
index 7b1dad091b1ae9ebfc6ba374cd659f9ddec9bd6c..6578bfc04c48aff00b8d07d164908f8e3d8a5f36 100644 (file)
@@ -325,17 +325,15 @@ doDisplayTable(std::string* ErrMsg) {
     if (Paths.empty() ||
         (std::find(Paths.begin(), Paths.end(), I->getPath()) != Paths.end())) {
       if (Verbose) {
-        // FIXME: Output should be this format:
-        // Zrw-r--r--  500/ 500    525 Nov  8 17:42 2004 Makefile
-        outs() << " ";
         unsigned mode = I->getMode();
         printMode((mode >> 6) & 007);
         printMode((mode >> 3) & 007);
         printMode(mode & 007);
-        outs() << " " << format("%4u", I->getUser());
-        outs() << "/" << format("%4u", I->getGroup());
-        outs() << " " << format("%8u", I->getSize());
-        outs() << " " << format("%20s", I->getModTime().str().substr(4).c_str());
+        outs() << ' ' << I->getUser();
+        outs() << "/" << I->getGroup();
+        outs() << ' ' << format("%6u", I->getSize());
+        sys::TimeValue ModTime = I->getModTime();
+        outs() << " " << ModTime.str();
         outs() << " " << I->getPath().str() << "\n";
       } else {
         outs() << I->getPath().str() << "\n";