4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
33 * Return number of entries in the section header array, taking
34 * extended headers into account.
36 * elf_getshnum() and elf_getshstrndx() were defined during the 2002 gABI
37 * meetings. They were supposed to return -1 for failure, and 0 for success.
38 * Our manpage documented them as such, but we then implemented them to
39 * return 0 for failure and 1 for success. This makes elf_getshnum() and
40 * elf_getshstrnum() non-portable to systems that implement the 2002 gABI
43 * In 2005, the manpage was modified to match the code.
44 * In 2009, the discrepency was identified. elf_getshdrnum() and
45 * elf_getshdrstrndx() were created to provide a portable implementation.
46 * The older two functions are considered to be obsolete, and are retained
47 * for backward compatability.
51 elf_getshdrnum(Elf
*elf
, size_t *shnum
)
57 if (gelf_getehdr(elf
, &ehdr
) == 0)
59 if (ehdr
.e_shnum
> 0) {
60 *shnum
= ehdr
.e_shnum
;
63 if ((ehdr
.e_shnum
== 0) && (ehdr
.e_shoff
== 0)) {
67 if ((scn
= elf_getscn(elf
, 0)) == 0)
69 if (gelf_getshdr(scn
, &shdr0
) == 0)
71 *shnum
= shdr0
.sh_size
;
76 elf_getshnum(Elf
*elf
, size_t *shnum
)
78 return (elf_getshdrnum(elf
, shnum
) == 0);