14484Sbinkertn@umich.edu/*-
24484Sbinkertn@umich.edu * Copyright (c) 2006 Joseph Koshy
34484Sbinkertn@umich.edu * All rights reserved.
44484Sbinkertn@umich.edu *
54484Sbinkertn@umich.edu * Redistribution and use in source and binary forms, with or without
64484Sbinkertn@umich.edu * modification, are permitted provided that the following conditions
74484Sbinkertn@umich.edu * are met:
84484Sbinkertn@umich.edu * 1. Redistributions of source code must retain the above copyright
94484Sbinkertn@umich.edu *    notice, this list of conditions and the following disclaimer.
104484Sbinkertn@umich.edu * 2. Redistributions in binary form must reproduce the above copyright
114484Sbinkertn@umich.edu *    notice, this list of conditions and the following disclaimer in the
124484Sbinkertn@umich.edu *    documentation and/or other materials provided with the distribution.
134484Sbinkertn@umich.edu *
144484Sbinkertn@umich.edu * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
154484Sbinkertn@umich.edu * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
164484Sbinkertn@umich.edu * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
174484Sbinkertn@umich.edu * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
184484Sbinkertn@umich.edu * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
194484Sbinkertn@umich.edu * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
204484Sbinkertn@umich.edu * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
214484Sbinkertn@umich.edu * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
224484Sbinkertn@umich.edu * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
234484Sbinkertn@umich.edu * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
244484Sbinkertn@umich.edu * SUCH DAMAGE.
254484Sbinkertn@umich.edu */
264484Sbinkertn@umich.edu
274484Sbinkertn@umich.edu#include "gelf.h"
284484Sbinkertn@umich.edu#include "libelf.h"
294484Sbinkertn@umich.edu#include "_libelf.h"
304484Sbinkertn@umich.edu
314484Sbinkertn@umich.eduvoid *
324484Sbinkertn@umich.edu_libelf_getshdr(Elf_Scn *s, int ec)
334484Sbinkertn@umich.edu{
344484Sbinkertn@umich.edu        Elf *e;
354484Sbinkertn@umich.edu
364484Sbinkertn@umich.edu        if (s == NULL || (e = s->s_elf) == NULL ||
374484Sbinkertn@umich.edu            e->e_kind != ELF_K_ELF) {
384484Sbinkertn@umich.edu                LIBELF_SET_ERROR(ARGUMENT, 0);
394484Sbinkertn@umich.edu                return (NULL);
404484Sbinkertn@umich.edu        }
414484Sbinkertn@umich.edu
424484Sbinkertn@umich.edu        if (ec == ELFCLASSNONE)
434484Sbinkertn@umich.edu                ec = e->e_class;
444484Sbinkertn@umich.edu
454484Sbinkertn@umich.edu        if (ec != e->e_class) {
464484Sbinkertn@umich.edu                LIBELF_SET_ERROR(CLASS, 0);
474484Sbinkertn@umich.edu                return (NULL);
484484Sbinkertn@umich.edu        }
494484Sbinkertn@umich.edu
504484Sbinkertn@umich.edu        return ((void *) &s->s_shdr);
514484Sbinkertn@umich.edu}
52