diff --git a/SystemTools.cxx b/SystemTools.cxx
index b87a002db0deed48582e942c27240eb3c5243e22..11f3b81aa26405d6eafd57cad412b4aab3a437cc 100644
--- a/SystemTools.cxx
+++ b/SystemTools.cxx
@@ -3797,11 +3797,7 @@ std::string SystemTools::GetFilenamePath(const std::string& filename)
  */
 std::string SystemTools::GetFilenameName(const std::string& filename)
 {
-#if defined(_WIN32)
   std::string::size_type slash_pos = filename.find_last_of("/\\");
-#else
-  std::string::size_type slash_pos = filename.rfind('/');
-#endif
   if (slash_pos != std::string::npos) {
     return filename.substr(slash_pos + 1);
   } else {
diff --git a/testSystemTools.cxx b/testSystemTools.cxx
index e6fbf6cdafb8ae2197ac3b815ff8b3e5c6535b72..1871f5dd0d81767d9cab71863184000d92cfd7de 100644
--- a/testSystemTools.cxx
+++ b/testSystemTools.cxx
@@ -758,6 +758,30 @@ static bool CheckGetPath()
   return res;
 }
 
+static bool CheckGetFilenameName()
+{
+  const char* windowsFilepath = "C:\\somewhere\\something";
+  const char* unixFilepath = "/somewhere/something";
+
+  std::string expectedFilename = "something";
+
+  bool res = true;
+  std::string filename = kwsys::SystemTools::GetFilenameName(windowsFilepath);
+  if (filename != expectedFilename) {
+    std::cerr << "GetFilenameName(" << windowsFilepath << ") yielded "
+              << filename << " instead of " << expectedFilename << std::endl;
+    res = false;
+  }
+
+  filename = kwsys::SystemTools::GetFilenameName(unixFilepath);
+  if (filename != expectedFilename) {
+    std::cerr << "GetFilenameName(" << unixFilepath << ") yielded " << filename
+              << " instead of " << expectedFilename << std::endl;
+    res = false;
+  }
+  return res;
+}
+
 static bool CheckFind()
 {
   bool res = true;
@@ -875,5 +899,7 @@ int testSystemTools(int, char* [])
 
   res &= CheckGetLineFromStream();
 
+  res &= CheckGetFilenameName();
+
   return res ? 0 : 1;
 }