Module: xenomai-3
Branch: master
Commit: 2e470e72b323411697aeb8ec31250581edc0cc9f
URL:    
http://git.xenomai.org/?p=xenomai-3.git;a=commit;h=2e470e72b323411697aeb8ec31250581edc0cc9f

Author: Philippe Gerum <r...@xenomai.org>
Date:   Thu Jul 23 09:56:07 2015 +0200

boilerplate/ancillaries: add command lookup routine

---

 include/boilerplate/ancillaries.h |    2 ++
 lib/boilerplate/ancillaries.c     |   24 ++++++++++++++++++++++++
 2 files changed, 26 insertions(+)

diff --git a/include/boilerplate/ancillaries.h 
b/include/boilerplate/ancillaries.h
index 47a025e..1ba320b 100644
--- a/include/boilerplate/ancillaries.h
+++ b/include/boilerplate/ancillaries.h
@@ -110,6 +110,8 @@ int get_static_cpu_count(void);
 
 pid_t get_thread_pid(void);
 
+char *lookup_command(const char *cmd);
+  
 #ifdef __cplusplus
 }
 #endif
diff --git a/lib/boilerplate/ancillaries.c b/lib/boilerplate/ancillaries.c
index 21aa667..3c6feef 100644
--- a/lib/boilerplate/ancillaries.c
+++ b/lib/boilerplate/ancillaries.c
@@ -25,6 +25,7 @@
 #include <unistd.h>
 #include <string.h>
 #include <errno.h>
+#include <malloc.h>
 #include "boilerplate/atomic.h"
 #include "boilerplate/lock.h"
 #include "boilerplate/time.h"
@@ -294,6 +295,29 @@ pid_t get_thread_pid(void)
        return syscall(__NR_gettid);
 }
 
+char *lookup_command(const char *cmd)
+{
+       const char *dirs[] = {
+               "/bin",
+               "/sbin",
+               "/usr/bin",
+               "/usr/sbin",
+       };
+       char *path;
+       int n, ret;
+
+       for (n = 0; n < sizeof(dirs) / sizeof(dirs[0]); n++) {
+               ret = asprintf(&path, "%s/%s", dirs[n], cmd);
+               if (ret < 0)
+                       return NULL;
+               if (access(path, X_OK) == 0)
+                       return path;
+               free(path);
+       }
+
+       return NULL;
+}
+
 const char *config_strings[] = {
 #include "config-dump.h"
        NULL,


_______________________________________________
Xenomai-git mailing list
Xenomai-git@xenomai.org
http://xenomai.org/mailman/listinfo/xenomai-git

Reply via email to