aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Lance Taylor <iant@google.com>2007-12-05 01:13:28 +0000
committerIan Lance Taylor <iant@google.com>2007-12-05 01:13:28 +0000
commit42a1b6860d6758d288f9b4a623122ae887e726aa (patch)
tree72dcda5dc8fb3157cf8ee1eca956488e7da61ce8
parent43771f76382f2d6f9faa6a8dd41d72b77f918b54 (diff)
downloadgdb-42a1b6860d6758d288f9b4a623122ae887e726aa.zip
gdb-42a1b6860d6758d288f9b4a623122ae887e726aa.tar.gz
gdb-42a1b6860d6758d288f9b4a623122ae887e726aa.tar.bz2
From Craig Silverstein: Support -o -.
-rw-r--r--gold/output.cc33
1 files changed, 21 insertions, 12 deletions
diff --git a/gold/output.cc b/gold/output.cc
index 420282a..6c4ed5c 100644
--- a/gold/output.cc
+++ b/gold/output.cc
@@ -1957,15 +1957,21 @@ Output_file::open(off_t file_size)
// If we fail, continue; this command is merely a best-effort attempt
// to improve the odds for open().
- struct stat s;
- if (::stat(this->name_, &s) == 0 && s.st_size != 0)
- unlink_if_ordinary(this->name_);
-
- int mode = parameters->output_is_object() ? 0666 : 0777;
- int o = ::open(this->name_, O_RDWR | O_CREAT | O_TRUNC, mode);
- if (o < 0)
- gold_fatal(_("%s: open: %s"), this->name_, strerror(errno));
- this->o_ = o;
+ // We let the name "-" mean "stdout"
+ if (strcmp(this->name_, "-") == 0)
+ this->o_ = STDOUT_FILENO;
+ else
+ {
+ struct stat s;
+ if (::stat(this->name_, &s) == 0 && s.st_size != 0)
+ unlink_if_ordinary(this->name_);
+
+ int mode = parameters->output_is_object() ? 0666 : 0777;
+ int o = ::open(this->name_, O_RDWR | O_CREAT | O_TRUNC, mode);
+ if (o < 0)
+ gold_fatal(_("%s: open: %s"), this->name_, strerror(errno));
+ this->o_ = o;
+ }
this->map();
}
@@ -2007,7 +2013,8 @@ Output_file::map()
// then later write the buffer to the file.
void* base;
struct stat statbuf;
- if (::fstat(o, &statbuf) != 0
+ if (o == STDOUT_FILENO || o == STDERR_FILENO
+ || ::fstat(o, &statbuf) != 0
|| !S_ISREG(statbuf.st_mode))
{
this->map_is_anonymous_ = true;
@@ -2065,8 +2072,10 @@ Output_file::close()
}
this->unmap();
- if (::close(this->o_) < 0)
- gold_error(_("%s: close: %s"), this->name_, strerror(errno));
+ // We don't close stdout or stderr
+ if (this->o_ != STDOUT_FILENO && this->o_ != STDERR_FILENO)
+ if (::close(this->o_) < 0)
+ gold_error(_("%s: close: %s"), this->name_, strerror(errno));
this->o_ = -1;
}