mirror of
https://github.com/tuxbox-fork-migrations/recycled-ni-neutrino.git
synced 2025-08-28 07:51:11 +02:00
helpers: add a function to find an executable in $PATH
Origin commit data
------------------
Branch: ni/coolstream
Commit: e37e425674
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:
@@ -290,6 +290,35 @@ bool get_mem_usage(unsigned long &kbtotal, unsigned long &kbfree)
|
|||||||
return true;
|
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)
|
std::string _getPathName(std::string &path, std::string sep)
|
||||||
{
|
{
|
||||||
size_t pos = path.find_last_of(sep);
|
size_t pos = path.find_last_of(sep);
|
||||||
|
@@ -41,6 +41,8 @@ bool get_fs_usage(const char * dir, uint64_t &btotal, uint64_t &bused, long *bsi
|
|||||||
bool get_mem_usage(unsigned long &total, unsigned long &free);
|
bool get_mem_usage(unsigned long &total, unsigned long &free);
|
||||||
void mySleep(int sec);
|
void mySleep(int sec);
|
||||||
|
|
||||||
|
std::string find_executable(const char *name);
|
||||||
|
|
||||||
std::string getPathName(std::string &path);
|
std::string getPathName(std::string &path);
|
||||||
std::string getBaseName(std::string &path);
|
std::string getBaseName(std::string &path);
|
||||||
std::string getFileName(std::string &file);
|
std::string getFileName(std::string &file);
|
||||||
|
Reference in New Issue
Block a user