|
22 | 22 | #include "absl/strings/str_replace.h" |
23 | 23 | #include "google/protobuf/io/io_win32.h" |
24 | 24 | #include "google/protobuf/testing/file.h" |
| 25 | +#include <gtest/gtest.h> |
| 26 | + |
25 | 27 | #ifdef _MSC_VER |
26 | 28 | // #include <direct.h> |
27 | 29 | #else |
@@ -93,45 +95,8 @@ std::string TestSourceDir() { |
93 | 95 | namespace { |
94 | 96 |
|
95 | 97 | std::string GetTemporaryDirectoryName() { |
96 | | - // Tests run under Bazel "should not" use /tmp. Bazel sets this environment |
97 | | - // variable for tests to use instead. |
98 | | - char* from_environment = getenv("TEST_TMPDIR"); |
99 | | - if (from_environment != nullptr && from_environment[0] != '\0') { |
100 | | - return absl::StrCat(from_environment, "/protobuf_tmpdir"); |
101 | | - } |
102 | | - |
103 | | - // tmpnam() is generally not considered safe but we're only using it for |
104 | | - // testing. We cannot use tmpfile() or mkstemp() since we're creating a |
105 | | - // directory. |
106 | | - char b[L_tmpnam + 1]; // HPUX multithread return 0 if s is 0 |
107 | | -#pragma GCC diagnostic push |
108 | | -#pragma GCC diagnostic ignored "-Wdeprecated-declarations" |
109 | | - std::string result = tmpnam(b); |
110 | | -#pragma GCC diagnostic pop |
| 98 | + std::string result = absl::StrCat(testing::TempDir(), "protobuf_tempdir"); |
111 | 99 | #ifdef _WIN32 |
112 | | - // Avoid a trailing dot by changing it to an underscore. On Win32 the names of |
113 | | - // files and directories can, but should not, end with dot. |
114 | | - // |
115 | | - // In MS-DOS and FAT16 filesystem the filenames were 8dot3 style so it didn't |
116 | | - // make sense to have a name ending in dot without an extension, so the shell |
117 | | - // silently ignored trailing dots. To this day the Win32 API still maintains |
118 | | - // this behavior and silently ignores trailing dots in path arguments of |
119 | | - // functions such as CreateFile{A,W}. Even POSIX API function implementations |
120 | | - // seem to wrap the Win32 API functions (e.g. CreateDirectoryA) and behave |
121 | | - // this way. |
122 | | - // It's possible to avoid this behavior and create files / directories with |
123 | | - // trailing dots (using CreateFileW / CreateDirectoryW and prefixing the path |
124 | | - // with "\\?\") but these will be degenerate in the sense that you cannot |
125 | | - // chdir into such directories (or navigate into them with Windows Explorer) |
126 | | - // nor can you open such files with some programs (e.g. Notepad). |
127 | | - if (result[result.size() - 1] == '.') { |
128 | | - result[result.size() - 1] = '_'; |
129 | | - } |
130 | | - // On Win32, tmpnam() returns a file prefixed with '\', but which is supposed |
131 | | - // to be used in the current working directory. WTF? |
132 | | - if (absl::StartsWith(result, "\\")) { |
133 | | - result.erase(0, 1); |
134 | | - } |
135 | 100 | // The Win32 API accepts forward slashes as a path delimiter as long as the |
136 | 101 | // path doesn't use the "\\?\" prefix. |
137 | 102 | // Let's avoid confusion and use only forward slashes. |
|
0 commit comments