]> pd.if.org Git - zpackage/blobdiff - elf/elftype.c
remove stray debug fprintf
[zpackage] / elf / elftype.c
index 7d3365da262463fd1e311cde15cdd435fc1f86a4..717dc122743b4492b935829a418b2d939c59afe0 100644 (file)
@@ -7,7 +7,7 @@
 
 #include <stdio.h>
 #include <stdlib.h>
-#include <elf.h>
+#include "elf.h"
 
 #define RELOCATABLE 0x1
 #define EXECUTABLE  0x2
@@ -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;
@@ -62,10 +60,24 @@ int main(int ac, char **av) {
        if (!want) want = (RELOCATABLE|EXECUTABLE|DYNAMIC|CORE);
 
        if (list) {
-               quiet = 2;
+               int type;
                perr = 0;
                while (readline(list, fn)) {
-                       if (checkfile(fn, want,perr,quiet)) {
+                       if ((type = checkfile(fn, want, perr)) & want) {
+                               if (printtype) {
+                                       switch (type) {
+                                               case RELOCATABLE:
+                                                       printf("relocatable "); break;
+                                               case EXECUTABLE:
+                                                       printf("executable "); break;
+                                               case DYNAMIC:
+                                                       printf("dynamic "); break;
+                                               case CORE:
+                                                       printf("core "); break;
+                                               default:
+                                                       printf("notelf "); break;
+                                       }
+                               }
                                printf("%s\n", fn);
                        }
                }
@@ -75,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) {
@@ -132,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;
@@ -155,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;
        }