elfcopy: select mode by the end of the program name
The mode of operation (elfcopy, mcs, or strip) is chosen based on the program name. Broaden this to allow a substring match at the end of the name to allow prefixes - for example, bsdstrip or aarch64-freebsd-strip. This improves use of these tools as drop-in replacements for GNU objcopy and strip, which are often built with a limited set of supported targets and installed with a target prefix for cross tools. Reviewed by: dim Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D1663
This commit is contained in:
parent
f104902826
commit
6c4cea19a9
@ -1529,6 +1529,22 @@ print_version(void)
|
||||
exit(EXIT_SUCCESS);
|
||||
}
|
||||
|
||||
/*
|
||||
* Compare the ending of s with end.
|
||||
*/
|
||||
static int
|
||||
strrcmp(const char *s, const char *end)
|
||||
{
|
||||
size_t endlen, slen;
|
||||
|
||||
slen = strlen(s);
|
||||
endlen = strlen(end);
|
||||
|
||||
if (slen >= endlen)
|
||||
s += slen - endlen;
|
||||
return (strcmp(s, end));
|
||||
}
|
||||
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
@ -1562,12 +1578,16 @@ main(int argc, char **argv)
|
||||
if ((ecp->progname = ELFTC_GETPROGNAME()) == NULL)
|
||||
ecp->progname = "elfcopy";
|
||||
|
||||
if (strcmp(ecp->progname, "strip") == 0)
|
||||
if (strrcmp(ecp->progname, "strip") == 0)
|
||||
strip_main(ecp, argc, argv);
|
||||
else if (strcmp(ecp->progname, "mcs") == 0)
|
||||
else if (strrcmp(ecp->progname, "mcs") == 0)
|
||||
mcs_main(ecp, argc, argv);
|
||||
else
|
||||
else {
|
||||
if (strrcmp(ecp->progname, "elfcopy") != 0 &&
|
||||
strrcmp(ecp->progname, "objcopy") != 0)
|
||||
warnx("program mode not known, defaulting to elfcopy");
|
||||
elfcopy_main(ecp, argc, argv);
|
||||
}
|
||||
|
||||
free_sec_add(ecp);
|
||||
free_sec_act(ecp);
|
||||
|
Loading…
Reference in New Issue
Block a user