llvm.org GIT mirror llvm / 76a74f7
Change MemoryBuffer::getFile to take a Twine. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@193429 91177308-0d34-0410-b5e6-96231b3b80d8 Rafael Espindola 5 years ago
3 changed file(s) with 15 addition(s) and 15 deletion(s). Raw diff Collapse all Expand all
1313 #ifndef LLVM_SUPPORT_MEMORYBUFFER_H
1414 #define LLVM_SUPPORT_MEMORYBUFFER_H
1515
16 #include "llvm/ADT/StringRef.h"
16 #include "llvm/ADT/Twine.h"
1717 #include "llvm/Support/CBindingWrapping.h"
1818 #include "llvm/Support/Compiler.h"
1919 #include "llvm/Support/DataTypes.h"
6565 /// MemoryBuffer if successful, otherwise returning null. If FileSize is
6666 /// specified, this means that the client knows that the file exists and that
6767 /// it has the specified size.
68 static error_code getFile(StringRef Filename, OwningPtr &result,
69 int64_t FileSize = -1,
70 bool RequiresNullTerminator = true);
71 static error_code getFile(const char *Filename,
72 OwningPtr &result,
68 static error_code getFile(Twine Filename, OwningPtr &result,
7369 int64_t FileSize = -1,
7470 bool RequiresNullTerminator = true);
7571
237237 return error_code::success();
238238 }
239239
240 error_code MemoryBuffer::getFile(StringRef Filename,
240 static error_code getFileAux(const char *Filename,
241 OwningPtr &result, int64_t FileSize,
242 bool RequiresNullTerminator);
243
244 error_code MemoryBuffer::getFile(Twine Filename,
241245 OwningPtr &result,
242246 int64_t FileSize,
243247 bool RequiresNullTerminator) {
244248 // Ensure the path is null terminated.
245 SmallString<256> PathBuf(Filename.begin(), Filename.end());
246 return MemoryBuffer::getFile(PathBuf.c_str(), result, FileSize,
247 RequiresNullTerminator);
249 SmallString<256> PathBuf;
250 StringRef NullTerminatedName = Filename.toNullTerminatedStringRef(PathBuf);
251 return getFileAux(NullTerminatedName.data(), result, FileSize,
252 RequiresNullTerminator);
248253 }
249254
250255 static error_code getOpenFileImpl(int FD, const char *Filename,
252257 uint64_t FileSize, uint64_t MapSize,
253258 int64_t Offset, bool RequiresNullTerminator);
254259
255 error_code MemoryBuffer::getFile(const char *Filename,
256 OwningPtr &result,
257 int64_t FileSize,
258 bool RequiresNullTerminator) {
260 static error_code getFileAux(const char *Filename,
261 OwningPtr &result, int64_t FileSize,
262 bool RequiresNullTerminator) {
259263 int FD;
260264 error_code EC = sys::fs::openFileForRead(Filename, FD);
261265 if (EC)
7878 OF.close();
7979
8080 OwningPtr MB;
81 error_code EC = MemoryBuffer::getFile(TestPath, MB);
81 error_code EC = MemoryBuffer::getFile(TestPath.c_str(), MB);
8282 ASSERT_FALSE(EC);
8383
8484 const char *BufData = MB->getBufferStart();