C++ runfiles test: fix on Linux

Change-Id: Iba231b4123cb1ed8ddd2d784d2d6b6ec331ba699

Closes #8879.

Change-Id: Iba231b4123cb1ed8ddd2d784d2d6b6ec331ba699
PiperOrigin-RevId: 257809080
diff --git a/tools/cpp/runfiles/runfiles_test.cc b/tools/cpp/runfiles/runfiles_test.cc
index 21c60b5..f29cc8a 100644
--- a/tools/cpp/runfiles/runfiles_test.cc
+++ b/tools/cpp/runfiles/runfiles_test.cc
@@ -129,6 +129,7 @@
   string path(tmp + "/" + name);
 
   string::size_type i = 0;
+#ifdef _WIN32
   while ((i = name.find_first_of("/\\", i + 1)) != string::npos) {
     string d = tmp + "\\" + name.substr(0, i);
     if (!CreateDirectoryA(d.c_str(), NULL)) {
@@ -137,6 +138,16 @@
       return nullptr;
     }
   }
+#else
+  while ((i = name.find_first_of('/', i + 1)) != string::npos) {
+    string d = tmp + "/" + name.substr(0, i);
+    if (mkdir(d.c_str(), 0777)) {
+      cerr << "ERROR: " << __FILE__ << "(" << __LINE__
+           << "): failed to create directory \"" << d << "\"" << endl;
+      return nullptr;
+    }
+  }
+#endif
 
   auto stm = std::ofstream(path);
   for (auto i : lines) {