mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2025-01-31 12:41:49 +01:00
[llvm] [unittest] Allow getting a C string from the TempDir helper class
The TempDir.path() member function returns a StringRef. We've been calling the data() method on that StringRef, which does not guarantee to return a null-terminated string (required by chdir and other POSIX functions). Introduce the c_str() method in the TempDir class, which returns the proper string without the need to create a copy of the path at use site.
This commit is contained in:
parent
18bea3ae49
commit
16b7e4e602
@ -152,6 +152,9 @@ public:
|
|||||||
/// The path to the temporary directory.
|
/// The path to the temporary directory.
|
||||||
StringRef path() const { return Path; }
|
StringRef path() const { return Path; }
|
||||||
|
|
||||||
|
/// The null-terminated C string pointing to the path.
|
||||||
|
const char *c_str() { return Path.c_str(); }
|
||||||
|
|
||||||
/// Creates a new path by appending the argument to the path of the managed
|
/// Creates a new path by appending the argument to the path of the managed
|
||||||
/// directory using the native path separator.
|
/// directory using the native path separator.
|
||||||
SmallString<128> path(StringRef component) const {
|
SmallString<128> path(StringRef component) const {
|
||||||
|
@ -81,7 +81,7 @@ TEST(LockFileManagerTest, RelativePath) {
|
|||||||
|
|
||||||
char PathBuf[1024];
|
char PathBuf[1024];
|
||||||
const char *OrigPath = getcwd(PathBuf, 1024);
|
const char *OrigPath = getcwd(PathBuf, 1024);
|
||||||
ASSERT_FALSE(chdir(LockFileManagerTestDir.path().data()));
|
ASSERT_FALSE(chdir(LockFileManagerTestDir.c_str()));
|
||||||
|
|
||||||
TempDir inner("inner");
|
TempDir inner("inner");
|
||||||
SmallString<64> LockedFile(inner.path());
|
SmallString<64> LockedFile(inner.path());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user