summaryrefslogtreecommitdiffstats
path: root/llvm/lib/System
diff options
context:
space:
mode:
authorChris Lattner <sabre@nondot.org>2006-07-18 06:57:51 +0000
committerChris Lattner <sabre@nondot.org>2006-07-18 06:57:51 +0000
commitfe5b7fe6d92c0ef6cf6bf5906797b5a279c00dfe (patch)
tree246b3c2cdbb379cf60db3658d19c5eebf35443fd /llvm/lib/System
parent3eb42b7d14a06a35ea04bdb0ca69af6bbcec763b (diff)
downloadbcm5719-llvm-fe5b7fe6d92c0ef6cf6bf5906797b5a279c00dfe.tar.gz
bcm5719-llvm-fe5b7fe6d92c0ef6cf6bf5906797b5a279c00dfe.zip
Reduce code in the error path by only allocating info_ if everything looks
good. llvm-svn: 29170
Diffstat (limited to 'llvm/lib/System')
-rw-r--r--llvm/lib/System/Unix/MappedFile.inc18
1 files changed, 8 insertions, 10 deletions
diff --git a/llvm/lib/System/Unix/MappedFile.inc b/llvm/lib/System/Unix/MappedFile.inc
index d194908a30e..8cd2a969473 100644
--- a/llvm/lib/System/Unix/MappedFile.inc
+++ b/llvm/lib/System/Unix/MappedFile.inc
@@ -43,7 +43,6 @@ void MappedFile::initialize() {
if (!path_.exists())
throw std::string("Can't open file: ") + path_.toString();
- info_ = new MappedFileInfo;
int mode = 0;
if (options_&READ_ACCESS)
if (options_&WRITE_ACCESS)
@@ -52,20 +51,19 @@ void MappedFile::initialize() {
mode = O_RDONLY;
else if (options_&WRITE_ACCESS)
mode = O_WRONLY;
- info_->fd_ = ::open(path_.c_str(),mode);
- if (info_->fd_ < 0) {
- delete info_;
- info_ = 0;
+ int FD = ::open(path_.c_str(), mode);
+ if (FD < 0)
ThrowErrno(std::string("Can't open file: ") + path_.toString());
- }
+
struct stat sbuf;
- if(::fstat(info_->fd_, &info_->sbuf_) < 0) {
- ::close(info_->fd_);
- delete info_;
- info_ = 0;
+ if(::fstat(FD, &sbuf) < 0) {
+ ::close(FD);
ThrowErrno(std::string("Can't stat file: ") + path_.toString());
}
+ info_ = new MappedFileInfo;
+ info_->fd_ = FD;
+ info_->sbuf_ = sbuf;
}
void MappedFile::terminate() {
OpenPOWER on IntegriCloud