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 | |
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')
-rw-r--r-- | usr.bin/brandelf/brandelf.1 | 5 | ||||
-rw-r--r-- | usr.bin/brandelf/brandelf.c | 53 |
2 files changed, 46 insertions, 12 deletions
diff --git a/usr.bin/brandelf/brandelf.1 b/usr.bin/brandelf/brandelf.1 index 2c4e820..c7d69b3 100644 --- a/usr.bin/brandelf/brandelf.1 +++ b/usr.bin/brandelf/brandelf.1 @@ -36,6 +36,7 @@ .Sh SYNOPSIS .Nm brandelf .Op Fl f +.Op Fl l .Op Fl v .Op Fl t Ar string .Ar file ... @@ -48,6 +49,8 @@ The options are as follows: .It Fl f forces branding even if the brand requested is unknown, and disables warnings for unknown brands. +.It Fl l +lists all known ELF types on the standard error channel. .It Fl v turns on verbose reporting .It Fl t Ar string @@ -78,7 +81,7 @@ command: .Sh DIAGNOSTICS Exit status is 0 on success, and 1 if the command fails if a file doesn't exist, is too short, fails to brand properly, -or the brand requested is not 'Linux' or 'FreeBSD' and the +or the brand requested is not one of the known types and the .Fl f option is not set. .Sh HISTORY 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"); +} |