diff options
author | wes <wes@FreeBSD.org> | 2000-01-04 02:33:54 +0000 |
---|---|---|
committer | wes <wes@FreeBSD.org> | 2000-01-04 02:33:54 +0000 |
commit | 24d00c85e402d3980b152dd5f762e5e2f8e7b26a (patch) | |
tree | a7c7cf3572396f67ece315a0e45cdb92c6daa398 /usr.bin/brandelf/brandelf.c | |
parent | 6af7f84af3fa2c3783aee573c4fe82ea78bd0e17 (diff) | |
download | FreeBSD-src-24d00c85e402d3980b152dd5f762e5e2f8e7b26a.zip FreeBSD-src-24d00c85e402d3980b152dd5f762e5e2f8e7b26a.tar.gz |
Make brandelf explain itself a little better on error.
Also, at Boris' suggestion, add -l option to list known
ELF types.
PR: bin/15285
Reviewed by: bp
Diffstat (limited to 'usr.bin/brandelf/brandelf.c')
-rw-r--r-- | usr.bin/brandelf/brandelf.c | 53 |
1 files changed, 42 insertions, 11 deletions
diff --git a/usr.bin/brandelf/brandelf.c b/usr.bin/brandelf/brandelf.c index cea6480..65b473d 100644 --- a/usr.bin/brandelf/brandelf.c +++ b/usr.bin/brandelf/brandelf.c @@ -37,6 +37,7 @@ #include <err.h> static int iselftype(const char *); +static void printelftypes(void); static void usage __P((void)); int @@ -45,13 +46,17 @@ main(int argc, char **argv) const char *type = "FreeBSD"; int retval = 0; - int ch, change = 0, verbose = 0, force = 0; + int ch, change = 0, verbose = 0, force = 0, listed = 0; - while ((ch = getopt(argc, argv, "ft:v")) != -1) + while ((ch = getopt(argc, argv, "flt:v")) != -1) switch (ch) { case 'f': force = 1; break; + case 'l': + printelftypes(); + listed = 1; + break; case 'v': verbose = 1; break; @@ -64,11 +69,20 @@ main(int argc, char **argv) } argc -= optind; argv += optind; - if (!argc) - errx(1, "no file(s) specified"); + if (!argc) { + if (listed) + exit(0); + else { + warnx("no file(s) specified"); + usage(); + } + } - if (!force && !iselftype(type)) - errx(1, "invalid ELF type '%s'", type); + if (!force && !iselftype(type)) { + warnx("invalid ELF type '%s'", type); + printelftypes(); + usage(); + } while (argc) { int fd; @@ -98,9 +112,11 @@ main(int argc, char **argv) fprintf(stdout, "File '%s' is of brand '%s'.\n", argv[0], string); - if (!force && !iselftype(string)) + if (!force && !iselftype(string)) { warnx("Brand '%s' is unknown", string); + printelftypes(); + } } else fprintf(stdout, "File '%s' has no branding.\n", @@ -126,14 +142,16 @@ fail: static void usage() { - fprintf(stderr, "usage: brandelf [-f] [-v] [-t string] file ...\n"); + fprintf(stderr, "usage: brandelf [-f] [-v] [-l] [-t string] file ...\n"); exit(1); } +/* XXX - any more types? */ +static const char *elftypes[] = { "FreeBSD", "Linux", "SVR4" }; + static int -iselftype(const char *elftype) { - /* XXX - any more types? */ - const char *elftypes[] = { "FreeBSD", "Linux", "SVR4" }; +iselftype(const char *elftype) +{ int elfwalk; for (elfwalk = 0; @@ -143,3 +161,16 @@ iselftype(const char *elftype) { return 1; return 0; } + +static void +printelftypes() +{ + int elfwalk; + + fprintf(stderr, "known ELF types are: "); + for (elfwalk = 0; + elfwalk < sizeof(elftypes)/sizeof(elftypes[0]); + elfwalk++) + fprintf(stderr, "%s ", elftypes[elfwalk]); + fprintf(stderr, "\n"); +} |