Use the actual uid/gid for defaulting the fields in the archive.
[oota-llvm.git] / lib / Archive / Archive.cpp
index a3fb534c9c36433a7661c7997b97cbce34e0bb4d..cb8bd2dbfdd613a8c41c39a6101d3ef1e83fbf87 100644 (file)
@@ -14,6 +14,7 @@
 
 #include "ArchiveInternals.h"
 #include "llvm/ModuleProvider.h"
+#include "llvm/System/Process.h"
 
 using namespace llvm;
 
@@ -26,7 +27,7 @@ ArchiveMember::getMemberSize() const {
 
   // If it has a long filename, include the name length
   if (hasLongFilename())
-    result += path.get().length() + 1;
+    result += path.toString().length() + 1;
 
   // If its now odd lengthed, include the padding byte
   if (result % 2 != 0 ) 
@@ -40,8 +41,8 @@ ArchiveMember::getMemberSize() const {
 ArchiveMember::ArchiveMember() 
   : next(0), prev(0), parent(0), path("<invalid>"), flags(0), data(0)
 {
-  info.user = 1000;
-  info.group = 1000
+  info.user = sys::Process::GetCurrentUserId();
+  info.group = sys::Process::GetCurrentGroupId()
   info.mode = 0777; 
   info.fileSize = 0; 
   info.modTime = sys::TimeValue::now();
@@ -65,33 +66,39 @@ void ArchiveMember::replaceWith(const sys::Path& newFile) {
   data = 0;
   path = newFile;
 
-  // Foreign symbol tables have an empty name
-  if (path.get() == ARFILE_SYMTAB_NAME)
-    flags |= ForeignSymbolTableFlag;
+  // SVR4 symbol tables have an empty name
+  if (path.toString() == ARFILE_SVR4_SYMTAB_NAME)
+    flags |= SVR4SymbolTableFlag;
   else
-    flags &= ~ForeignSymbolTableFlag;
+    flags &= ~SVR4SymbolTableFlag;
+
+  // BSD4.4 symbol tables have a special name
+  if (path.toString() == ARFILE_BSD4_SYMTAB_NAME)
+    flags |= BSD4SymbolTableFlag;
+  else
+    flags &= ~BSD4SymbolTableFlag;
 
   // LLVM symbol tables have a very specific name
-  if (path.get() == ARFILE_LLVM_SYMTAB_NAME)
+  if (path.toString() == ARFILE_LLVM_SYMTAB_NAME)
     flags |= LLVMSymbolTableFlag;
   else
     flags &= ~LLVMSymbolTableFlag;
 
   // String table name
-  if (path.get() == ARFILE_STRTAB_NAME)
+  if (path.toString() == ARFILE_STRTAB_NAME)
     flags |= StringTableFlag;
   else
     flags &= ~StringTableFlag;
 
   // If it has a slash then it has a path
-  bool hasSlash = path.get().find('/') != std::string::npos;
+  bool hasSlash = path.toString().find('/') != std::string::npos;
   if (hasSlash)
     flags |= HasPathFlag;
   else
     flags &= ~HasPathFlag;
 
   // If it has a slash or its over 15 chars then its a long filename format
-  if (hasSlash || path.get().length() > 15)
+  if (hasSlash || path.toString().length() > 15)
     flags |= HasLongFilenameFlag;
   else
     flags &= ~HasLongFilenameFlag;
@@ -137,7 +144,7 @@ Archive::Archive(const sys::Path& filename, bool map )
 Archive::~Archive() {
   // Shutdown the file mapping
   if (mapfile) {
-    mapfile->unmap();
+    mapfile->close();
     delete mapfile;
   }
   // Delete any ModuleProviders and ArchiveMember's we've allocated as a result