2009-10-22 Hui Zhu <teawater@gmail.com>
[deliverable/binutils-gdb.git] / gold / descriptors.cc
index b05bdf1a89d1031d9e7313bd41f5e5281662b952..f4a02d03296caaf2cc1b6eeaf12204785b31ac12 100644 (file)
@@ -23,6 +23,7 @@
 #include "gold.h"
 
 #include <cerrno>
+#include <cstdio>
 #include <cstring>
 #include <fcntl.h>
 #include <unistd.h>
@@ -31,6 +32,7 @@
 #include "options.h"
 #include "gold-threads.h"
 #include "descriptors.h"
+#include "binary-io.h"
 
 // Very old systems may not define FD_CLOEXEC.
 #ifndef FD_CLOEXEC
@@ -51,8 +53,8 @@ namespace gold
 // adjusted downward if we run out of file descriptors.
 
 Descriptors::Descriptors()
-  : lock_(NULL), open_descriptors_(), stack_top_(-1), current_(0),
-    limit_(8192 - 16)
+  : lock_(NULL), initialize_lock_(&this->lock_), open_descriptors_(),
+    stack_top_(-1), current_(0), limit_(8192 - 16)
 {
   this->open_descriptors_.reserve(128);
 }
@@ -66,13 +68,9 @@ Descriptors::open(int descriptor, const char* name, int flags, int mode)
   // initialize a Lock until we have parsed the options to find out
   // whether we are running with threads.  We can be called before
   // options are valid when reading a linker script.
-  if (this->lock_ == NULL)
-    {
-      if (parameters->options_valid())
-       this->lock_ = new Lock();
-      else
-       gold_assert(descriptor < 0);
-    }
+  bool lock_initialized = this->initialize_lock_.initialize();
+
+  gold_assert(lock_initialized || descriptor < 0);
 
   if (descriptor >= 0)
     {
@@ -102,6 +100,9 @@ Descriptors::open(int descriptor, const char* name, int flags, int mode)
       // require callers to pass it.
       flags |= O_CLOEXEC;
 
+      // Always open the file as a binary file.
+      flags |= O_BINARY;
+
       int new_descriptor = ::open(name, flags, mode);
       if (new_descriptor < 0
          && errno != ENFILE
This page took 0.023732 seconds and 4 git commands to generate.