1 /* Copyright (C) 2007 Red Hat, Inc.
2 This file is part of elfutils.
4 This file is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3 of the License, or
7 (at your option) any later version.
9 elfutils is distributed in the hope that it will be useful, but
10 WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
24 static int handle (const char *fname);
28 main (int argc, char *argv[])
30 elf_version (EV_CURRENT);
34 result = handle ("a.out");
36 for (int i = 1; i < argc; ++i)
37 result |= handle (argv[1]);
44 handle (const char *fname)
46 int fd = open (fname, O_RDONLY);
49 printf ("cannot open '%s': %m\n", fname);
53 Elf *elf = elf_begin (fd, ELF_C_READ_MMAP, NULL);
56 printf ("cannot get ELF handling for '%s': %s\n",
57 fname, elf_errmsg (-1));
62 if (elf_kind (elf) != ELF_K_AR)
64 printf ("'%s' is no archive\n", fname);
70 printf ("%s:\n", fname);
72 Elf_Cmd cmd = ELF_C_READ_MMAP;
73 while ((subelf = elf_begin (fd, cmd, elf)) != NULL)
75 Elf_Arhdr *arhdr = elf_getarhdr (subelf);
78 printf ("cannot get archive header in '%s': %s\n",
79 fname, elf_errmsg (-1));
86 off_t off = elf_getaroff (subelf);
88 printf ("\nOffset %llu\n"
95 (unsigned long long int) off,
96 arhdr->ar_name, (long int) arhdr->ar_date, (int) arhdr->ar_uid,
98 (int) arhdr->ar_mode, (long long int) arhdr->ar_size);
100 cmd = elf_next (subelf);