1365eb6c25e09e784bc8bd3e41abb6e5bb5a3803
[centaur.git] / src / elfops / section-name.c
1 #include <stdlib.h>
2
3 #include <libelf.h>
4 #include <gelf.h>
5
6 #include <libelfu/libelfu.h>
7
8
9 char* elfu_sectionName(Elf *e, Elf_Scn *scn)
10 {
11   size_t shstrndx;
12   GElf_Shdr shdr;
13
14   if (elf_getshdrstrndx(e, &shstrndx) != 0) {
15     return NULL;
16   }
17
18   if (gelf_getshdr(scn, &shdr) != &shdr) {
19     return NULL;
20   }
21
22   /* elf_strptr returns NULL if there was an error */
23   return elf_strptr(e, shstrndx, shdr.sh_name);
24 }