1203287Srnoland/*- 2203287Srnoland * Copyright (c) 2006 Joseph Koshy 3203287Srnoland * All rights reserved. 4203287Srnoland * 5203287Srnoland * Redistribution and use in source and binary forms, with or without 6203287Srnoland * modification, are permitted provided that the following conditions 7203287Srnoland * are met: 8203287Srnoland * 1. Redistributions of source code must retain the above copyright 9203287Srnoland * notice, this list of conditions and the following disclaimer. 10203287Srnoland * 2. Redistributions in binary form must reproduce the above copyright 11203287Srnoland * notice, this list of conditions and the following disclaimer in the 12203287Srnoland * documentation and/or other materials provided with the distribution. 13203287Srnoland * 14203287Srnoland * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15203287Srnoland * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16203287Srnoland * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17203287Srnoland * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18203287Srnoland * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19203287Srnoland * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20203287Srnoland * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21203287Srnoland * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22203287Srnoland * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23203287Srnoland * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24203287Srnoland * SUCH DAMAGE. 25203287Srnoland */ 26203287Srnoland 27203287Srnoland#include <sys/cdefs.h> 28203287Srnoland__FBSDID("$FreeBSD$"); 29203287Srnoland 30203287Srnoland#include <ar.h> 31203287Srnoland#include <libelf.h> 32203287Srnoland 33203287Srnoland#include "_libelf.h" 34203287Srnoland 35203287Srnolandstatic int 36203287Srnoland_libelf_getshdrnum(Elf *e, size_t *shnum) 37203287Srnoland{ 38203287Srnoland void *eh; 39203287Srnoland int ec; 40203287Srnoland 41203287Srnoland if (e == NULL || e->e_kind != ELF_K_ELF || 42203287Srnoland ((ec = e->e_class) != ELFCLASS32 && ec != ELFCLASS64)) { 43203287Srnoland LIBELF_SET_ERROR(ARGUMENT, 0); 44203287Srnoland return (-1); 45203287Srnoland } 46203287Srnoland 47203287Srnoland if ((eh = _libelf_ehdr(e, ec, 0)) == NULL) 48203287Srnoland return (-1); 49203287Srnoland 50203287Srnoland *shnum = e->e_u.e_elf.e_nscn; 51203287Srnoland 52203287Srnoland return (0); 53203287Srnoland} 54203287Srnoland 55203287Srnolandint 56203287Srnolandelf_getshdrnum(Elf *e, size_t *shnum) 57203287Srnoland{ 58203287Srnoland return (_libelf_getshdrnum(e, shnum)); 59203287Srnoland} 60203287Srnoland 61203287Srnoland/* Deprecated API. */ 62203287Srnolandint 63203287Srnolandelf_getshnum(Elf *e, size_t *shnum) 64203287Srnoland{ 65203287Srnoland return (_libelf_getshdrnum(e, shnum) >= 0); 66203287Srnoland} 67203287Srnoland