Skip to content
Snippets Groups Projects
Commit 9596e98d authored by Rolf Eike Beer's avatar Rolf Eike Beer Committed by Brad King
Browse files

SystemTools: move some code around that is used only on Windows-like platforms

The list of possible extensions is only filled inside an #ifdef, so the whole
usage of this list can be moved into that #ifdef's, too. The loop can be
completely avoided if it's already known that the list will not be filled at
all.

Change-Id: I89a87115babf68f9bf99d4ad523cb0851c252cd9
parent 0adafb51
No related branches found
No related tags found
No related merge requests found
......@@ -2970,6 +2970,8 @@ std::string SystemTools::FindProgram(
bool no_system_path)
{
std::vector<std::string> extensions;
std::string tryPath;
#if defined (_WIN32) || defined(__CYGWIN__) || defined(__MINGW32__)
bool hasExtension = false;
// check to see if the name already has a .xxx at
......@@ -2983,22 +2985,22 @@ std::string SystemTools::FindProgram(
{
extensions.push_back(".com");
extensions.push_back(".exe");
}
#endif
std::string tryPath;
// first try with extensions if the os supports them
for(std::vector<std::string>::iterator i =
extensions.begin(); i != extensions.end(); ++i)
{
tryPath = name;
tryPath += *i;
if(SystemTools::FileExists(tryPath) &&
!SystemTools::FileIsDirectory(tryPath))
// first try with extensions if the os supports them
for(std::vector<std::string>::iterator i =
extensions.begin(); i != extensions.end(); ++i)
{
return SystemTools::CollapseFullPath(tryPath);
tryPath = name;
tryPath += *i;
if(SystemTools::FileExists(tryPath) &&
!SystemTools::FileIsDirectory(tryPath))
{
return SystemTools::CollapseFullPath(tryPath);
}
}
}
#endif
// now try just the name
tryPath = name;
if(SystemTools::FileExists(tryPath) &&
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment