|
a/src/utils/execmd.cpp |
|
b/src/utils/execmd.cpp |
|
... |
|
... |
66 |
return true;
|
66 |
return true;
|
67 |
}
|
67 |
}
|
68 |
return false;
|
68 |
return false;
|
69 |
}
|
69 |
}
|
70 |
|
70 |
|
71 |
bool ExecCmd::which(const string& cmd, string& path)
|
71 |
bool ExecCmd::which(const string& cmd, string& exepath, const char* path)
|
72 |
{
|
72 |
{
|
73 |
if (cmd.empty())
|
73 |
if (cmd.empty())
|
74 |
return false;
|
74 |
return false;
|
75 |
if (cmd[0] == '/') {
|
75 |
if (cmd[0] == '/') {
|
76 |
if (exec_is_there(cmd.c_str())) {
|
76 |
if (exec_is_there(cmd.c_str())) {
|
77 |
path = cmd;
|
77 |
exepath = cmd;
|
78 |
return true;
|
78 |
return true;
|
79 |
} else {
|
79 |
} else {
|
80 |
return false;
|
80 |
return false;
|
81 |
}
|
81 |
}
|
82 |
}
|
82 |
}
|
83 |
|
83 |
|
84 |
const char *pp = getenv("PATH");
|
84 |
const char *pp;
|
|
|
85 |
if (path) {
|
|
|
86 |
pp = path;
|
|
|
87 |
} else {
|
|
|
88 |
pp = getenv("PATH");
|
|
|
89 |
}
|
85 |
if (pp == 0)
|
90 |
if (pp == 0)
|
86 |
return false;
|
91 |
return false;
|
|
|
92 |
|
87 |
list<string> pels;
|
93 |
list<string> pels;
|
88 |
stringToTokens(pp, pels, ":");
|
94 |
stringToTokens(pp, pels, ":");
|
89 |
for (list<string>::iterator it = pels.begin(); it != pels.end(); it++) {
|
95 |
for (list<string>::iterator it = pels.begin(); it != pels.end(); it++) {
|
90 |
if (it->empty())
|
96 |
if (it->empty())
|
91 |
*it = ".";
|
97 |
*it = ".";
|
92 |
string candidate = (it->empty() ? string(".") : *it) + "/" + cmd;
|
98 |
string candidate = (it->empty() ? string(".") : *it) + "/" + cmd;
|
93 |
if (exec_is_there(candidate.c_str())) {
|
99 |
if (exec_is_there(candidate.c_str())) {
|
94 |
path = candidate;
|
100 |
exepath = candidate;
|
95 |
return true;
|
101 |
return true;
|
96 |
}
|
102 |
}
|
97 |
}
|
103 |
}
|
98 |
return false;
|
104 |
return false;
|
99 |
}
|
105 |
}
|