1elf_strptr(3ELF) ELF Library Functions elf_strptr(3ELF)
2
3
4
6 elf_strptr - make a string pointer
7
9 cc [ flag ... ] file ... -lelf [ library ... ]
10 #include <libelf.h>
11
12 char *elf_strptr(Elf *elf, size_t section, size_t offset);
13
14
16 The elf_strptr() function converts a string section offset to a string
17 pointer. elf identifies the file in which the string section resides,
18 and section identifies the section table index for the strings.
19 elf_strptr() normally returns a pointer to a string, but it returns a
20 null pointer when elf is null, section is invalid or is not a section
21 of type SHT_STRTAB, the section data cannot be obtained, offset is
22 invalid, or an error occurs.
23
25 Example 1 A sample program of calling elf_strptr() function.
26
27
28 A prototype for retrieving section names appears below. The file header
29 specifies the section name string table in the e_shstrndx member. The
30 following code loops through the sections, printing their names.
31
32
33 /* handle the error */
34 if ((ehdr = elf32_getehdr(elf)) == 0) {
35 return;
36 }
37 ndx = ehdr->e_shstrndx;
38 scn = 0;
39 while ((scn = elf_nextscn(elf, scn)) != 0) {
40 char *name = 0;
41 if ((shdr = elf32_getshdr(scn)) != 0)
42 name = elf_strptr(elf, ndx, (size_t)shdr->sh_name);
43 printf("'%s'\n", name? name: "(null)");
44 }
45
46
48 See attributes(5) for descriptions of the following attributes:
49
50
51
52
53 ┌─────────────────────────────┬─────────────────────────────┐
54 │ ATTRIBUTE TYPE │ ATTRIBUTE VALUE │
55 ├─────────────────────────────┼─────────────────────────────┤
56 │Interface Stability │Stable │
57 ├─────────────────────────────┼─────────────────────────────┤
58 │MT-Level │MT-Safe │
59 └─────────────────────────────┴─────────────────────────────┘
60
62 elf(3ELF), elf32_getshdr(3ELF), elf32_xlatetof(3ELF), elf_get‐
63 data(3ELF), libelf(3LIB), attributes(5)
64
66 A program may call elf_getdata() to retrieve an entire string table
67 section. For some applications, that would be both more efficient and
68 more convenient than using elf_strptr().
69
70
71
72SunOS 5.11 11 Jul 2001 elf_strptr(3ELF)