mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-02-23 22:15:25 +00:00
Change MemoryBuffer::getFile to take a Twine.
llvm-svn: 193429
This commit is contained in:
parent
949cb82c41
commit
1587321957
@ -14,7 +14,7 @@
|
|||||||
#ifndef LLVM_SUPPORT_MEMORYBUFFER_H
|
#ifndef LLVM_SUPPORT_MEMORYBUFFER_H
|
||||||
#define 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/CBindingWrapping.h"
|
||||||
#include "llvm/Support/Compiler.h"
|
#include "llvm/Support/Compiler.h"
|
||||||
#include "llvm/Support/DataTypes.h"
|
#include "llvm/Support/DataTypes.h"
|
||||||
@ -66,11 +66,7 @@ public:
|
|||||||
/// MemoryBuffer if successful, otherwise returning null. If FileSize is
|
/// MemoryBuffer if successful, otherwise returning null. If FileSize is
|
||||||
/// specified, this means that the client knows that the file exists and that
|
/// specified, this means that the client knows that the file exists and that
|
||||||
/// it has the specified size.
|
/// it has the specified size.
|
||||||
static error_code getFile(StringRef Filename, OwningPtr<MemoryBuffer> &result,
|
static error_code getFile(Twine Filename, OwningPtr<MemoryBuffer> &result,
|
||||||
int64_t FileSize = -1,
|
|
||||||
bool RequiresNullTerminator = true);
|
|
||||||
static error_code getFile(const char *Filename,
|
|
||||||
OwningPtr<MemoryBuffer> &result,
|
|
||||||
int64_t FileSize = -1,
|
int64_t FileSize = -1,
|
||||||
bool RequiresNullTerminator = true);
|
bool RequiresNullTerminator = true);
|
||||||
|
|
||||||
|
@ -238,14 +238,19 @@ static error_code getMemoryBufferForStream(int FD,
|
|||||||
return error_code::success();
|
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,
|
OwningPtr<MemoryBuffer> &result,
|
||||||
int64_t FileSize,
|
int64_t FileSize,
|
||||||
bool RequiresNullTerminator) {
|
bool RequiresNullTerminator) {
|
||||||
// Ensure the path is null terminated.
|
// Ensure the path is null terminated.
|
||||||
SmallString<256> PathBuf(Filename.begin(), Filename.end());
|
SmallString<256> PathBuf;
|
||||||
return MemoryBuffer::getFile(PathBuf.c_str(), result, FileSize,
|
StringRef NullTerminatedName = Filename.toNullTerminatedStringRef(PathBuf);
|
||||||
RequiresNullTerminator);
|
return getFileAux(NullTerminatedName.data(), result, FileSize,
|
||||||
|
RequiresNullTerminator);
|
||||||
}
|
}
|
||||||
|
|
||||||
static error_code getOpenFileImpl(int FD, const char *Filename,
|
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,
|
uint64_t FileSize, uint64_t MapSize,
|
||||||
int64_t Offset, bool RequiresNullTerminator);
|
int64_t Offset, bool RequiresNullTerminator);
|
||||||
|
|
||||||
error_code MemoryBuffer::getFile(const char *Filename,
|
static error_code getFileAux(const char *Filename,
|
||||||
OwningPtr<MemoryBuffer> &result,
|
OwningPtr<MemoryBuffer> &result, int64_t FileSize,
|
||||||
int64_t FileSize,
|
bool RequiresNullTerminator) {
|
||||||
bool RequiresNullTerminator) {
|
|
||||||
int FD;
|
int FD;
|
||||||
error_code EC = sys::fs::openFileForRead(Filename, FD);
|
error_code EC = sys::fs::openFileForRead(Filename, FD);
|
||||||
if (EC)
|
if (EC)
|
||||||
|
@ -79,7 +79,7 @@ TEST_F(MemoryBufferTest, NullTerminator4K) {
|
|||||||
OF.close();
|
OF.close();
|
||||||
|
|
||||||
OwningPtr<MemoryBuffer> MB;
|
OwningPtr<MemoryBuffer> MB;
|
||||||
error_code EC = MemoryBuffer::getFile(TestPath, MB);
|
error_code EC = MemoryBuffer::getFile(TestPath.c_str(), MB);
|
||||||
ASSERT_FALSE(EC);
|
ASSERT_FALSE(EC);
|
||||||
|
|
||||||
const char *BufData = MB->getBufferStart();
|
const char *BufData = MB->getBufferStart();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user