This is the mail archive of the
elfutils-devel@sourceware.org
mailing list for the elfutils project.
Re: AR archive iteration broken?
- From: Roland McGrath <roland at redhat dot com>
- To: elfutils-devel at lists dot fedorahosted dot org
- Date: Sun, 01 Nov 2009 19:33:44 -0800
- Subject: Re: AR archive iteration broken?
Are you aware of a different libelf implementation (e.g. Solaris) where
your test program works as you expect?
The normal idiom for archive iteration is to use the return value from
elf_next, rather than ignoring it. It returns ELF_C_NULL when there is no
later element. You don't need to test that return value directly unless
you want to. The normal idiom is to pass that return value in to
elf_begin, and ELF_C_NULL to elf_begin just returns NULL. e.g.:
Elf_Cmd cmd = ELF_C_READ;
while ((subelf = elf_begin (fd, cmd, elf)) != NULL)
{
Elf_Arhdr *arhdr = elf_getarhdr (subelf);
... work on subelf ...
/* Get next archive element. */
cmd = elf_next (subelf);
if (elf_end (subelf) != 0)
... diagnose error ...;
}
Thanks,
Roland