mirror of
https://github.com/tuxbox-fork-migrations/recycled-ni-neutrino.git
synced 2025-08-27 15:32:52 +02:00
helpers: add a function to find an executable in $PATH
Origin commit data
------------------
Branch: ni/coolstream
Commit: 1867f687b8
Author: Stefan Seyfried <seife@tuxbox-git.slipkontur.de>
Date: 2014-01-26 (Sun, 26 Jan 2014)
------------------
No further description and justification available within origin commit message!
------------------
This commit was generated by Migit
This commit is contained in:
@@ -291,6 +291,35 @@ bool get_mem_usage(unsigned long &kbtotal, unsigned long &kbfree)
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string find_executable(const char *name)
|
||||
{
|
||||
struct stat s;
|
||||
char *path = getenv("PATH");
|
||||
char *p, *n;
|
||||
if (! path)
|
||||
path = strdupa("/bin:/usr/bin:/sbin:/usr/sbin");
|
||||
if (name[0] == '/') { /* full path given */
|
||||
if (!access(name, X_OK) && !stat(name, &s) && S_ISREG(s.st_mode))
|
||||
return std::string(name);
|
||||
return "";
|
||||
}
|
||||
|
||||
p = path;
|
||||
while (p) {
|
||||
n = strchr(p, ':');
|
||||
if (n)
|
||||
*n++ = '\0';
|
||||
if (*p != '\0') {
|
||||
std::string tmp = std::string(p) + "/" + std::string(name);
|
||||
const char *f = tmp.c_str();
|
||||
if (!access(f, X_OK) && !stat(f, &s) && S_ISREG(s.st_mode))
|
||||
return tmp;
|
||||
}
|
||||
p = n;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
std::string _getPathName(std::string &path, std::string sep)
|
||||
{
|
||||
size_t pos = path.find_last_of(sep);
|
||||
|
Reference in New Issue
Block a user