diff options
author | Anders Roxell <anders.roxell@linaro.org> | 2019-03-16 00:39:13 +0100 |
---|---|---|
committer | Anders Roxell <anders.roxell@linaro.org> | 2019-03-16 00:39:13 +0100 |
commit | 6baab2ddab6b19e2fae1bdd084b9d9888c2d1d8f (patch) | |
tree | 0f507cc5d6a7cae159f8eabf97601a8c9e31e66a | |
parent | 6ee9581d2f9d28a35902845873ca6767c08c5d82 (diff) |
new committesting
Signed-off-by: Anders Roxell <anders.roxell@linaro.org>
-rw-r--r-- | tests/gpiod-test.c | 40 |
1 files changed, 37 insertions, 3 deletions
diff --git a/tests/gpiod-test.c b/tests/gpiod-test.c index 4c51f4a..e513720 100644 --- a/tests/gpiod-test.c +++ b/tests/gpiod-test.c @@ -449,14 +449,48 @@ static void gpiotool_proc_dup_fds(int in_fd, int out_fd, int err_fd) static char *gpiotool_proc_get_path(const char *tool) { - char *path, *progpath, *progdir; + char *progpath, *progdir, *toolpath, *pathenv, *tok; + /* + * First check if we're running the tool from the top source + * directory. + */ progpath = xstrdup(program_invocation_name); progdir = dirname(progpath); - path = xappend(NULL, "%s/../../tools/%s", progdir, tool); + + toolpath = xappend(NULL, "%s/../../tools/%s", progdir, tool); + if (access(toolpath, R_OK | X_OK) == 0) + goto out; + free(toolpath); + + /* Is the tool in the same directory maybe? */ + toolpath = xappend(NULL, "%s/%s", progdir, tool); + if (access(toolpath, R_OK | X_OK) == 0) + goto out; + free(toolpath); free(progpath); - return path; + /* Next iterate over directories in $PATH. */ + pathenv = getenv("PATH"); + if (!pathenv) + return NULL; + + progpath = xstrdup(pathenv); + tok = strtok(progpath, ":"); + while (tok) { + toolpath = xappend(NULL, "%s/%s", tok, tool); + if (access(toolpath, R_OK) == 0) + goto out; + + free(toolpath); + tok = strtok(NULL, ":"); + } + + toolpath = NULL; + +out: + free(progpath); + return toolpath; } static NORETURN void gpiotool_proc_exec(const char *path, va_list va) |