forked from OSchip/llvm-project
Change MemoryBuffer::getFile to take a Twine.
llvm-svn: 193429
This commit is contained in:
parent
1a3605cdbe
commit
1d19c8f03a
|
@ -14,7 +14,7 @@
|
|||
#ifndef LLVM_SUPPORT_MEMORYBUFFER_H
|
||||
#define LLVM_SUPPORT_MEMORYBUFFER_H
|
||||
|
||||
#include "llvm/ADT/StringRef.h"
|
||||
#include "llvm/ADT/Twine.h"
|
||||
#include "llvm/Support/CBindingWrapping.h"
|
||||
#include "llvm/Support/Compiler.h"
|
||||
#include "llvm/Support/DataTypes.h"
|
||||
|
@ -66,11 +66,7 @@ public:
|
|||
/// MemoryBuffer if successful, otherwise returning null. If FileSize is
|
||||
/// specified, this means that the client knows that the file exists and that
|
||||
/// it has the specified size.
|
||||
static error_code getFile(StringRef Filename, OwningPtr<MemoryBuffer> &result,
|
||||
int64_t FileSize = -1,
|
||||
bool RequiresNullTerminator = true);
|
||||
static error_code getFile(const char *Filename,
|
||||
OwningPtr<MemoryBuffer> &result,
|
||||
static error_code getFile(Twine Filename, OwningPtr<MemoryBuffer> &result,
|
||||
int64_t FileSize = -1,
|
||||
bool RequiresNullTerminator = true);
|
||||
|
||||
|
|
|
@ -238,14 +238,19 @@ static error_code getMemoryBufferForStream(int FD,
|
|||
return error_code::success();
|
||||
}
|
||||
|
||||
error_code MemoryBuffer::getFile(StringRef Filename,
|
||||
static error_code getFileAux(const char *Filename,
|
||||
OwningPtr<MemoryBuffer> &result, int64_t FileSize,
|
||||
bool RequiresNullTerminator);
|
||||
|
||||
error_code MemoryBuffer::getFile(Twine Filename,
|
||||
OwningPtr<MemoryBuffer> &result,
|
||||
int64_t FileSize,
|
||||
bool RequiresNullTerminator) {
|
||||
// Ensure the path is null terminated.
|
||||
SmallString<256> PathBuf(Filename.begin(), Filename.end());
|
||||
return MemoryBuffer::getFile(PathBuf.c_str(), result, FileSize,
|
||||
RequiresNullTerminator);
|
||||
SmallString<256> PathBuf;
|
||||
StringRef NullTerminatedName = Filename.toNullTerminatedStringRef(PathBuf);
|
||||
return getFileAux(NullTerminatedName.data(), result, FileSize,
|
||||
RequiresNullTerminator);
|
||||
}
|
||||
|
||||
static error_code getOpenFileImpl(int FD, const char *Filename,
|
||||
|
@ -253,10 +258,9 @@ static error_code getOpenFileImpl(int FD, const char *Filename,
|
|||
uint64_t FileSize, uint64_t MapSize,
|
||||
int64_t Offset, bool RequiresNullTerminator);
|
||||
|
||||
error_code MemoryBuffer::getFile(const char *Filename,
|
||||
OwningPtr<MemoryBuffer> &result,
|
||||
int64_t FileSize,
|
||||
bool RequiresNullTerminator) {
|
||||
static error_code getFileAux(const char *Filename,
|
||||
OwningPtr<MemoryBuffer> &result, int64_t FileSize,
|
||||
bool RequiresNullTerminator) {
|
||||
int FD;
|
||||
error_code EC = sys::fs::openFileForRead(Filename, FD);
|
||||
if (EC)
|
||||
|
|
|
@ -79,7 +79,7 @@ TEST_F(MemoryBufferTest, NullTerminator4K) {
|
|||
OF.close();
|
||||
|
||||
OwningPtr<MemoryBuffer> MB;
|
||||
error_code EC = MemoryBuffer::getFile(TestPath, MB);
|
||||
error_code EC = MemoryBuffer::getFile(TestPath.c_str(), MB);
|
||||
ASSERT_FALSE(EC);
|
||||
|
||||
const char *BufData = MB->getBufferStart();
|
||||
|
|
Loading…
Reference in New Issue