DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH
 

elf_strptr(S)


elf_strptr -- make a string pointer

Syntax

cc [flag . . . ] file . . . -lelf [library] . . .

#include <libelf.h>

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

Description

elf_strptr(S) converts a string section offset to a string pointer. elf identifies the file that the string section is in, and section gives the section table index for the strings. elf_strptr( ) normally returns a pointer to a string.

Return values

elf_strptr( ) returns a pointer to a string or NULL. It returns a null pointer under the following conditions:

Diagnostics

Error conditions are identified through the routine elf_error(S).

Examples

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.

   if ((ehdr = elf32_getehdr(elf)) == 0)
   {
   	/* handle the error */
   	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'\n", name? name: "(null)");
   }

Warning

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

See also

elf(S), elf_getdata(S), elf_getshdr(S), elf_xlate(S)

Standards conformance

elf_strptr(S) is not part of any currently supported standard; it was developed by UNIX System Laboratories, Inc. and is maintained by The SCO Group.
© 2003 Caldera International, Inc. All rights reserved.
SCO OpenServer Release 5.0.7 -- 11 February 2003