From 7ef90a15dd4531a53f6db0738fd7df1073484ed5 Mon Sep 17 00:00:00 2001 From: Nathan Wagner Date: Fri, 12 Oct 2018 22:28:38 +0000 Subject: [PATCH] add elftype as zpm-elftype --- .gitignore | 1 - Makefile | 7 ++++--- elf/elftype.c | 15 ++++++--------- 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/.gitignore b/.gitignore index 9274c88..70122a6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ -elftype *.o *.a *~ diff --git a/Makefile b/Makefile index d5d19c1..75e3b8e 100644 --- a/Makefile +++ b/Makefile @@ -28,7 +28,8 @@ curdir=$(shell pwd) ZPKGBIN=zpm-addfile zpm-extract zpm-init zpm-vercmp zpm-stat zpm-hash \ zpm-findpkg zpm-shell zpm-soneed zpm-foreach-path zpm-parse \ - zpm-runscript zpm-soname zpm-syncfs zpm-packagehash zpm-verify + zpm-runscript zpm-soname zpm-syncfs zpm-packagehash zpm-verify \ + zpm-elftype SCRIPTS=zpm zpm-install zpm-merge zpm-list zpm-preserve zpm-test zpm-log \ zpm-contents zpm-uninstall zpm-pathmod @@ -102,8 +103,8 @@ programs: $(ZPKGBIN) uncompress: uncompress.o $(CC) $(CFLAGS) -o $@ $+ -llzma -elftype: elf/elftype.c - $(CC) $(CFLAGS) -o $@ $+ +zpm-elftype: elf/elftype.c + $(CC) -Ielf $(CFLAGS) -o $@ $+ zpm-soname: elf/soname.c $(CC) -Ielf $(CFLAGS) -o $@ $+ diff --git a/elf/elftype.c b/elf/elftype.c index d9b253a..717dc12 100644 --- a/elf/elftype.c +++ b/elf/elftype.c @@ -16,7 +16,7 @@ #define SYMLINKS 0x10 int readline(FILE *f, char *fn); -int checkfile(char *fn, unsigned int want, int perr, int quiet); +int checkfile(char *fn, unsigned int want, int perr); int errors = 0; int zeroterm = 0; @@ -24,7 +24,6 @@ int zeroterm = 0; int main(int ac, char **av) { int option; unsigned int want = 0; - int quiet = 0; int printtype = 0; int printname = 0; int verbose = 0; @@ -32,7 +31,7 @@ int main(int ac, char **av) { FILE *list = 0; char fn[PATH_MAX]; - while ((option = getopt(ac, av, "vtnredclaqp0f:")) != -1) { + while ((option = getopt(ac, av, "vtnredclap0f:")) != -1) { switch (option) { case 'r': want |= RELOCATABLE; break; case 'e': want |= EXECUTABLE; break; @@ -40,7 +39,6 @@ int main(int ac, char **av) { case 'c': want |= CORE; break; case 'l': want |= SYMLINKS; break; case 'a': want = (RELOCATABLE|EXECUTABLE|DYNAMIC|CORE); break; - case 'q': quiet++; break; case 't': printtype++; break; case 'n': printname++; break; case 'v': verbose++; break; @@ -63,10 +61,9 @@ int main(int ac, char **av) { if (list) { int type; - quiet = 2; perr = 0; while (readline(list, fn)) { - if ((type = checkfile(fn, want,perr,quiet)) & want) { + if ((type = checkfile(fn, want, perr)) & want) { if (printtype) { switch (type) { case RELOCATABLE: @@ -90,7 +87,7 @@ int main(int ac, char **av) { fn = av[optind]; if (verbose) fprintf(stderr, "checking %s\n", av[optind]); - type = checkfile(fn,want,perr,quiet); + type = checkfile(fn,want,perr); if (printtype) { switch (type) { @@ -147,7 +144,7 @@ int readline(FILE *f, char *fn) { return 0; } -int checkfile(char *fn, unsigned int want, int perr, int quiet) { +int checkfile(char *fn, unsigned int want, int perr) { Elf64_Ehdr hdr; int fd, bytes; int endian = 0; @@ -170,7 +167,7 @@ int checkfile(char *fn, unsigned int want, int perr, int quiet) { } bytes = read(fd, &hdr, sizeof hdr); close(fd); - if (bytes < sizeof hdr) { + if ((size_t)bytes < sizeof hdr) { if (perr) fprintf(stderr, "could not read full elf header (wanted %zu got %d bytes)\n", sizeof hdr, bytes); return 0; } -- 2.40.0