elf_getarhdr.c revision 302408
1135446Strhodes/*-
2262706Serwin * Copyright (c) 2006,2008,2010 Joseph Koshy
3135446Strhodes * All rights reserved.
4135446Strhodes *
5193149Sdougb * Redistribution and use in source and binary forms, with or without
6135446Strhodes * modification, are permitted provided that the following conditions
7135446Strhodes * are met:
8135446Strhodes * 1. Redistributions of source code must retain the above copyright
9135446Strhodes *    notice, this list of conditions and the following disclaimer.
10135446Strhodes * 2. Redistributions in binary form must reproduce the above copyright
11135446Strhodes *    notice, this list of conditions and the following disclaimer in the
12135446Strhodes *    documentation and/or other materials provided with the distribution.
13135446Strhodes *
14135446Strhodes * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15135446Strhodes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16135446Strhodes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17135446Strhodes * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18254897Serwin * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19135446Strhodes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20170222Sdougb * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21170222Sdougb * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22135446Strhodes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23135446Strhodes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24135446Strhodes * SUCH DAMAGE.
25193149Sdougb */
26135446Strhodes
27135446Strhodes#include <libelf.h>
28135446Strhodes
29135446Strhodes#include "_libelf.h"
30193149Sdougb
31135446StrhodesELFTC_VCSID("$Id: elf_getarhdr.c 3174 2015-03-27 17:13:41Z emaste $");
32193149Sdougb
33193149SdougbElf_Arhdr *
34193149Sdougbelf_getarhdr(Elf *e)
35193149Sdougb{
36193149Sdougb	if (e == NULL) {
37135446Strhodes		LIBELF_SET_ERROR(ARGUMENT, 0);
38135446Strhodes		return (NULL);
39135446Strhodes	}
40135446Strhodes
41135446Strhodes	if (e->e_flags & LIBELF_F_AR_HEADER)
42135446Strhodes		return (e->e_hdr.e_arhdr);
43135446Strhodes
44135446Strhodes	return (_libelf_ar_gethdr(e));
45135446Strhodes}
46135446Strhodes