8322 nl: misleading-indentation
[unleashed/tickless.git] / usr / src / cmd / sgs / libelf / common / getshstrndx.c
blob4b981c5fe4d00471f24419f7fe5ed27983356364
1 /*
2 * CDDL HEADER START
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]
19 * CDDL HEADER END
22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #include <string.h>
27 #include <gelf.h>
28 #include <decl.h>
29 #include <msg.h>
32 * Return section header array string table index, taking
33 * extended headers into account.
35 * elf_getshstrndx() returns 0 for failure, and 1 for success.
37 * elf_getshdrstrndx() supercedes elf_getshstrndx(), which is now considered
38 * obsolete. It returns -1 for failure and 0 for success, bringing us into
39 * alignment with the interface agreed to in the 2002 gABI meeting.
41 * See the comment in getshnum.c for additional information.
44 int
45 elf_getshdrstrndx(Elf *elf, size_t *shstrndx)
47 GElf_Ehdr ehdr;
48 Elf_Scn *scn;
49 GElf_Shdr shdr0;
51 if (gelf_getehdr(elf, &ehdr) == 0)
52 return (-1);
53 if (ehdr.e_shstrndx != SHN_XINDEX) {
54 *shstrndx = ehdr.e_shstrndx;
55 return (0);
57 if ((scn = elf_getscn(elf, 0)) == 0)
58 return (-1);
59 if (gelf_getshdr(scn, &shdr0) == 0)
60 return (-1);
61 *shstrndx = shdr0.sh_link;
62 return (0);
65 int
66 elf_getshstrndx(Elf *elf, size_t *shstrndx)
68 return (elf_getshdrstrndx(elf, shstrndx) == 0);