xref: /titanic_50/usr/src/man/man3elf/elf_strptr.3elf (revision fe77cc0407fb667ddc04e1a8f2e203bb7b9c80e1)
te
Copyright 1989 AT&T Copyright (c) 2001, Sun Microsystems, Inc. All Rights Reserved
The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License.
You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License.
When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
ELF_STRPTR 3ELF "Jul 11, 2001"
NAME
elf_strptr - make a string pointer
SYNOPSIS

cc [ flag ... ] file ... -lelf [ library ... ]
#include <libelf.h>

char *elf_strptr(Elf *elf, size_t section, size_t offset);
DESCRIPTION

The elf_strptr() function converts a string section offset to a string pointer. elf identifies the file in which the string section resides, and section identifies the section table index for the strings. elf_strptr() normally returns a pointer to a string, but it returns a null pointer when elf is null, section is invalid or is not a section of type SHT_STRTAB, the section data cannot be obtained, offset is invalid, or an error occurs.

EXAMPLES

Example 1 A sample program of calling elf_strptr() function.

A prototype for retrieving section names appears below. The file header specifies the section name string table in the e_shstrndx member. The following code loops through the sections, printing their names.

/* handle the error */
if ((ehdr = elf32_getehdr(elf)) == 0) {
 return;
}
ndx = ehdr->e_shstrndx;
scn = 0;
while ((scn = elf_nextscn(elf, scn)) != 0) {
 char *name = 0;
 if ((shdr = elf32_getshdr(scn)) != 0)
 name = elf_strptr(elf, ndx, (size_t)shdr->sh_name);
 printf("'%s'\en", name? name: "(null)");
}
ATTRIBUTES

See attributes(5) for descriptions of the following attributes:

ATTRIBUTE TYPE ATTRIBUTE VALUE
Interface Stability Stable
MT-Level MT-Safe
SEE ALSO

elf(3ELF), elf32_getshdr(3ELF), elf32_xlatetof(3ELF), elf_getdata(3ELF), libelf(3LIB), attributes(5)

NOTES

A program may call elf_getdata() to retrieve an entire string table section. For some applications, that would be both more efficient and more convenient than using elf_strptr().