Author: emaste Date: Sun Mar 8 20:35:00 2020 New Revision: 358778 URL: https://svnweb.freebsd.org/changeset/base/358778
Log: readelf: hoist file opening out of dump_object Diff reduction with HEAD to facilitate other MFCs. Modified: stable/12/contrib/elftoolchain/readelf/readelf.c Modified: stable/12/contrib/elftoolchain/readelf/readelf.c ============================================================================== --- stable/12/contrib/elftoolchain/readelf/readelf.c Sun Mar 8 20:09:19 2020 (r358777) +++ stable/12/contrib/elftoolchain/readelf/readelf.c Sun Mar 8 20:35:00 2020 (r358778) @@ -7116,15 +7116,8 @@ process_members: } static void -dump_object(struct readelf *re) +dump_object(struct readelf *re, int fd) { - int fd; - - if ((fd = open(re->filename, O_RDONLY)) == -1) { - warn("open %s failed", re->filename); - return; - } - if ((re->flags & DISPLAY_FILENAME) != 0) printf("\nFile: %s\n", re->filename); @@ -7145,13 +7138,10 @@ dump_object(struct readelf *re) break; default: warnx("Internal: libelf returned unknown elf kind."); - goto done; } - elf_end(re->elf); - done: - close(fd); + elf_end(re->elf); } static void @@ -7496,7 +7486,7 @@ main(int argc, char **argv) { struct readelf *re, re_storage; unsigned long si; - int opt, i; + int fd, opt, i; char *ep; re = &re_storage; @@ -7621,7 +7611,13 @@ main(int argc, char **argv) for (i = 0; i < argc; i++) { re->filename = argv[i]; - dump_object(re); + fd = open(re->filename, O_RDONLY); + if (fd < 0) { + warn("open %s failed", re->filename); + } else { + dump_object(re, fd); + close(fd); + } } exit(EXIT_SUCCESS); _______________________________________________ svn-src-all@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-all To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"