SCP: Prefer Posix 'command -v' over 'which'

This commit is contained in:
Mark Pizzolato 2021-12-04 11:48:49 -08:00
parent ab6c2c043e
commit 3621db4e6a

19
scp.c
View file

@ -6411,8 +6411,10 @@ FILE *f;
#define popen _popen #define popen _popen
#define pclose _pclose #define pclose _pclose
#else #else
#define FIND_CMD "which" #define FIND_CMD "command -v"
#define FIND_CMD2 "" #define FIND_CMD2 "2>/dev/null"
#define FIND_CMD_EXTRA "which"
#define FIND_CMD2_EXTRA "2>/dev/null"
#endif #endif
memset (toolpath, 0, sizeof(toolpath)); memset (toolpath, 0, sizeof(toolpath));
snprintf (findcmd, sizeof (findcmd), "%s %s %s", FIND_CMD, tool, FIND_CMD2); 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'); } while (toolpath[0] == '\0');
pclose (f); 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; return toolpath;
} }