SCP: Prefer Posix 'command -v' over 'which'
This commit is contained in:
parent
ab6c2c043e
commit
3621db4e6a
1 changed files with 17 additions and 2 deletions
19
scp.c
19
scp.c
|
@ -6411,8 +6411,10 @@ FILE *f;
|
|||
#define popen _popen
|
||||
#define pclose _pclose
|
||||
#else
|
||||
#define FIND_CMD "which"
|
||||
#define FIND_CMD2 ""
|
||||
#define FIND_CMD "command -v"
|
||||
#define FIND_CMD2 "2>/dev/null"
|
||||
#define FIND_CMD_EXTRA "which"
|
||||
#define FIND_CMD2_EXTRA "2>/dev/null"
|
||||
#endif
|
||||
memset (toolpath, 0, sizeof(toolpath));
|
||||
snprintf (findcmd, sizeof (findcmd), "%s %s %s", FIND_CMD, tool, FIND_CMD2);
|
||||
|
@ -6424,6 +6426,19 @@ if ((f = popen (findcmd, "r"))) {
|
|||
} while (toolpath[0] == '\0');
|
||||
pclose (f);
|
||||
}
|
||||
if (toolpath[0] == '\0') { /* Not found yet? */
|
||||
#if defined(FIND_CMD_EXTRA) /* Try with alternative command */
|
||||
snprintf (findcmd, sizeof (findcmd), "%s %s %s", FIND_CMD_EXTRA, tool, FIND_CMD2_EXTRA);
|
||||
if ((f = popen (findcmd, "r"))) {
|
||||
do {
|
||||
if (NULL == fgets (toolpath, sizeof(toolpath)-1, f))
|
||||
break;
|
||||
sim_trim_endspc (toolpath);
|
||||
} while (toolpath[0] == '\0');
|
||||
pclose (f);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
return toolpath;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue