[Commits] : Tuxbox-GIT: apps branch master updated. CVS-Final-523-g6b89af1
Tuxbox Sources
Brought to you by:
dbt1
|
From: GetAway <tux...@ne...> - 2015-04-13 07:52:44
|
Project "Tuxbox-GIT: apps":
The branch, master has been updated
via 6b89af1d88bb6106ac17b9ae6d002f1980bf1127 (commit)
from 1b4373ed942e3d89d6985f5476015158405a15d8 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 6b89af1d88bb6106ac17b9ae6d002f1980bf1127
Author: Stefan Seyfried <se...@tu...>
Date: Mon Apr 13 09:48:59 2015 +0200
helper: add a function to find an executable in $PATH
Signed-off-by: GetAway <get...@t-...>
diff --git a/tuxbox/neutrino/src/system/helper.cpp b/tuxbox/neutrino/src/system/helper.cpp
index 66505f4..cb7a065 100644
--- a/tuxbox/neutrino/src/system/helper.cpp
+++ b/tuxbox/neutrino/src/system/helper.cpp
@@ -122,3 +122,34 @@ int my_system(int argc, const char *arg, ...)
va_end(args);
return ret;
}
+
+std::string find_executable(const char *name)
+{
+ struct stat s;
+ char *tmpPath = getenv("PATH");
+ char *p, *n, *path;
+ if (tmpPath)
+ path = strdupa(tmpPath);
+ else
+ path = strdupa("/bin:/var/bin:/sbin:/var/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 "";
+}
diff --git a/tuxbox/neutrino/src/system/helper.h b/tuxbox/neutrino/src/system/helper.h
index 5fd8de4..8ccc836 100644
--- a/tuxbox/neutrino/src/system/helper.h
+++ b/tuxbox/neutrino/src/system/helper.h
@@ -34,4 +34,6 @@ int my_system(int argc, const char *arg, ...); /* argc is number of arguments in
bool file_exists(const char *filename);
+std::string find_executable(const char *name);
+
#endif
-----------------------------------------------------------------------
Summary of changes:
tuxbox/neutrino/src/system/helper.cpp | 31 +++++++++++++++++++++++++++++++
tuxbox/neutrino/src/system/helper.h | 2 ++
2 files changed, 33 insertions(+), 0 deletions(-)
--
Tuxbox-GIT: apps
|