diff options
author | Joseph Hunkeler <jhunkeler@gmail.com> | 2020-09-03 00:47:14 -0400 |
---|---|---|
committer | Joseph Hunkeler <jhunkeler@gmail.com> | 2020-09-03 00:47:14 -0400 |
commit | b10833eafe987234b5da51051400a0e515e54146 (patch) | |
tree | eb04814fa8c8bf14bfd21476f5430d411f6d3d46 | |
parent | d7c435e5b7c12012668484f84c14425fa08cf9fc (diff) | |
download | multihome-b10833eafe987234b5da51051400a0e515e54146.tar.gz |
find_program() returns the absolute path if it begins with "./"
-rw-r--r-- | multihome.c | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/multihome.c b/multihome.c index d7a8fd3..12fc41a 100644 --- a/multihome.c +++ b/multihome.c @@ -126,6 +126,8 @@ split_die_2: /** * Using $PATH, return the location of _name * + * If _name starts with "./" return the absolute path to the file + * * This function returns local storage * * @param _name program name @@ -150,16 +152,24 @@ char *find_program(const char *_name) { memset(buf, '\0', sizeof(buf)); found = 0; - for (int i = 0; parts[i] != NULL; i++) { - char tmp[PATH_MAX]; - memset(tmp, '\0', sizeof(tmp)); - strcat(tmp, parts[i]); - strcat(tmp, "/"); - strcat(tmp, _name); - if (access(tmp, F_OK) == 0) { + + if (strncmp(_name, "./", 2) == 0) { + if (access(_name, F_OK) == 0) { found = 1; - realpath(tmp, buf); - break; + realpath(_name, buf); + } + } else { + for (int i = 0; parts[i] != NULL; i++) { + char tmp[PATH_MAX]; + memset(tmp, '\0', sizeof(tmp)); + strcat(tmp, parts[i]); + strcat(tmp, "/"); + strcat(tmp, _name); + if (access(tmp, F_OK) == 0) { + found = 1; + realpath(tmp, buf); + break; + } } } |