diff options
author | Chris Lattner <sabre@nondot.org> | 2007-05-06 23:32:36 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2007-05-06 23:32:36 +0000 |
commit | 275757a05ef6a506303fd3a240ea389c476a9777 (patch) | |
tree | 8e6ef2d20eb00e2703d0a5b999ababbe12adf148 /llvm/lib/Support | |
parent | 05be1d44da49f743c80d36c45a9515641824c318 (diff) | |
download | bcm5719-llvm-275757a05ef6a506303fd3a240ea389c476a9777.tar.gz bcm5719-llvm-275757a05ef6a506303fd3a240ea389c476a9777.zip |
Enhance MemoryBuffer to return error messages in strings if they occur.
llvm-svn: 36899
Diffstat (limited to 'llvm/lib/Support')
-rw-r--r-- | llvm/lib/Support/MemoryBuffer.cpp | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/llvm/lib/Support/MemoryBuffer.cpp b/llvm/lib/Support/MemoryBuffer.cpp index ffbb4beccfa..b2c561c77a0 100644 --- a/llvm/lib/Support/MemoryBuffer.cpp +++ b/llvm/lib/Support/MemoryBuffer.cpp @@ -113,7 +113,7 @@ class MemoryBufferMMapFile : public MemoryBuffer { public: MemoryBufferMMapFile() {} - bool open(const sys::Path &Filename); + bool open(const sys::Path &Filename, std::string *ErrStr); virtual const char *getBufferIdentifier() const { return File.path().c_str(); @@ -123,13 +123,15 @@ public: }; } -bool MemoryBufferMMapFile::open(const sys::Path &Filename) { +bool MemoryBufferMMapFile::open(const sys::Path &Filename, + std::string *ErrStr) { // FIXME: This does an extra stat syscall to figure out the size, but we // already know the size! - bool Failure = File.open(Filename); + bool Failure = File.open(Filename, sys::MappedFile::READ_ACCESS, ErrStr); if (Failure) return true; - File.map(); + if (!File.map(ErrStr)) + return true; size_t Size = File.size(); @@ -161,11 +163,13 @@ MemoryBufferMMapFile::~MemoryBufferMMapFile() { //===----------------------------------------------------------------------===// MemoryBuffer *MemoryBuffer::getFile(const char *FilenameStart, unsigned FnSize, - int64_t FileSize) { + std::string *ErrStr, int64_t FileSize){ + // FIXME: it would be nice if PathWithStatus didn't copy the filename into a + // temporary string. :( sys::PathWithStatus P(FilenameStart, FnSize); #if 1 MemoryBufferMMapFile *M = new MemoryBufferMMapFile(); - if (!M->open(P)) + if (!M->open(P, ErrStr)) return M; delete M; return 0; @@ -186,7 +190,7 @@ MemoryBuffer *MemoryBuffer::getFile(const char *FilenameStart, unsigned FnSize, // If the file is larger than some threshold, use mmap, otherwise use 'read'. if (FileSize >= 4096*4) { MemoryBufferMMapFile *M = new MemoryBufferMMapFile(); - if (!M->open(P)) + if (!M->open(P, ErrStr)) return M; delete M; return 0; |