diff options
author | Wes Peters <wes@FreeBSD.org> | 2000-01-04 02:33:54 +0000 |
---|---|---|
committer | Wes Peters <wes@FreeBSD.org> | 2000-01-04 02:33:54 +0000 |
commit | b5ce857bec268e922358411748c1b4a1affc930d (patch) | |
tree | 4511a7c69187d3aa5e1eae3a1bfaa0c767c176ee | |
parent | 9b8ea2242c53f537234613ca747550aaf213f75b (diff) | |
download | src-test2-b5ce857bec268e922358411748c1b4a1affc930d.tar.gz src-test2-b5ce857bec268e922358411748c1b4a1affc930d.zip |
Notes
-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 2c4e82091364..c7d69b378ab9 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 cea64801f598..65b473df5ebc 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"); +} |