MCPcopy Create free account
hub / github.com/GJDuck/e9patch / findBinary

Function findBinary

src/e9tool/e9misc.cpp:224–249  ·  view source on GitHub ↗

* Find an exe file in PATH. */

Source from the content-addressed store, hash-verified

222 * Find an exe file in PATH.
223 */
224const char *findBinary(const char *filename, bool exe, bool dot)
225{
226 if (filename[0] == '/' || filename[0] == '.')
227 return filename;
228 std::vector<std::string> path;
229 getPath(exe, path);
230 if (dot)
231 path.push_back(".");
232 for (const auto &dirname: path)
233 {
234 std::string pathname_0(dirname);
235 pathname_0 += '/';
236 pathname_0 += filename;
237
238 char *pathname = realpath(pathname_0.c_str(), nullptr);
239 if (pathname == nullptr)
240 continue;
241 struct stat buf;
242 if (stat(pathname, &buf) == 0 && (buf.st_mode & S_IXOTH) != 0)
243 return pathname;
244 free(pathname);
245 }
246
247 error("failed to find %s file \"%s\" in %s",
248 (exe? "executable": "library"), filename, (exe? "PATH": "RPATH"));
249}
250
251/*
252 * Usage.

Callers 2

spawnBackendFunction · 0.85
main_2Function · 0.85

Calls 4

getPathFunction · 0.85
freeFunction · 0.85
errorFunction · 0.85
statClass · 0.70

Tested by

no test coverage detected