This is the mail archive of the elfutils-devel@sourceware.org mailing list for the elfutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]