Home | History | Annotate | Download | only in libelf
      1 /* Read header of next archive member.
      2    Copyright (C) 1998, 1999, 2000, 2002 Red Hat, Inc.
      3    Written by Ulrich Drepper <drepper (at) redhat.com>, 1998.
      4 
      5    This program is free software; you can redistribute it and/or modify
      6    it under the terms of the GNU General Public License as published by
      7    the Free Software Foundation, version 2.
      8 
      9    This program is distributed in the hope that it will be useful,
     10    but 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.
     13 
     14    You should have received a copy of the GNU General Public License
     15    along with this program; if not, write to the Free Software Foundation,
     16    Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
     17 
     18 #ifdef HAVE_CONFIG_H
     19 # include <config.h>
     20 #endif
     21 
     22 #include <assert.h>
     23 #include <libelf.h>
     24 #include <stddef.h>
     25 
     26 #include "libelfP.h"
     27 
     28 
     29 Elf_Arhdr *
     30 elf_getarhdr (elf)
     31      Elf *elf;
     32 {
     33   Elf *parent = elf->parent;
     34 
     35   /* Calling this function is not ok for any file type but archives.  */
     36   if (parent == NULL)
     37     {
     38       __libelf_seterrno (ELF_E_INVALID_OP);
     39       return NULL;
     40     }
     41 
     42   /* Make sure we have read the archive header.  */
     43   if (parent->state.ar.elf_ar_hdr.ar_name == NULL
     44       && __libelf_next_arhdr (parent) != 0)
     45     /* Something went wrong.  Maybe there is no member left.  */
     46     return NULL;
     47 
     48 
     49   /* We can be sure the parent is an archive.  */
     50   assert (parent->kind == ELF_K_AR);
     51 
     52   return &parent->state.ar.elf_ar_hdr;
     53 }
     54