diff options
author | Taku Kudo <taku@google.com> | 2018-08-03 08:36:46 +0300 |
---|---|---|
committer | Taku Kudo <taku@google.com> | 2018-08-03 08:36:46 +0300 |
commit | 1caa5fb76eb41c7ce8bf17a67a1db7024d82e788 (patch) | |
tree | 9cd94115261e3927391561957315d194679be887 /src/testharness.cc | |
parent | a0b734a4a2a2259e346f5b602ba807c5deef2f0b (diff) |
Added JoinPath and StrCat
Diffstat (limited to 'src/testharness.cc')
-rw-r--r-- | src/testharness.cc | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/src/testharness.cc b/src/testharness.cc index afdfac3..35bf893 100644 --- a/src/testharness.cc +++ b/src/testharness.cc @@ -66,12 +66,24 @@ int RunAllTests() { return 0; } -ScopedTempFile::ScopedTempFile(const std::string &filename) { +ScopedTempFile::ScopedTempFile(absl::string_view filename) { char pid[64]; - snprintf(pid, sizeof(pid), "%u", getpid()); - filename_ = "/tmp/.XXX.tmp." + filename + "." + pid; + snprintf(pid, sizeof(pid), "%u", +#ifdef OS_WIN + static_cast<uint32>(::GetCurrentProcessId()) +#else + ::getpid() +#endif + ); + filename_ = string_util::StrCat(".XXX.tmp.", filename, ".", pid); } -ScopedTempFile::~ScopedTempFile() { ::unlink(filename_.c_str()); } +ScopedTempFile::~ScopedTempFile() { +#ifdef OS_WIN + ::DeleteFile(WPATH(filename_.c_str())); +#else + ::unlink(filename_.c_str()); +#endif +} } // namespace test } // namespace sentencepiece |