forked from OSchip/llvm-project
[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
844e94a502
commit
e7b40c5492
|
@ -152,6 +152,9 @@ public:
|
|||
/// The path to the temporary directory.
|
||||
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
|
||||
/// directory using the native path separator.
|
||||
SmallString<128> path(StringRef component) const {
|
||||
|
|
|
@ -81,7 +81,7 @@ TEST(LockFileManagerTest, RelativePath) {
|
|||
|
||||
char PathBuf[1024];
|
||||
const char *OrigPath = getcwd(PathBuf, 1024);
|
||||
ASSERT_FALSE(chdir(LockFileManagerTestDir.path().data()));
|
||||
ASSERT_FALSE(chdir(LockFileManagerTestDir.c_str()));
|
||||
|
||||
TempDir inner("inner");
|
||||
SmallString<64> LockedFile(inner.path());
|
||||
|
|
Loading…
Reference in New Issue