dutil: Move elf_section_by_name to dutil

Will be used by more than one file.

Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
Arnaldo Carvalho de Melo 2009-03-24 16:56:19 -03:00
parent 4848eef743
commit 8bf5eb9bc8
3 changed files with 22 additions and 17 deletions

View File

@ -55,23 +55,6 @@ struct ctf_state {
int in_fd;
};
static Elf_Scn *elf_section_by_name(Elf *elf, GElf_Ehdr *ep,
GElf_Shdr *shp, const char *name)
{
Elf_Scn *sec = NULL;
while ((sec = elf_nextscn(elf, sec)) != NULL) {
char *str;
gelf_getshdr(sec, shp);
str = elf_strptr(elf, ep->e_shstrndx, shp->sh_name);
if (!strcmp(name, str))
break;
}
return sec;
}
struct elf_sym_iter_state {
int (*func)(struct ctf_state *sp, const char *sym_name,
int sym_index, int call_index, void *data);

17
dutil.c
View File

@ -108,3 +108,20 @@ int strlist__has_entry(const struct strlist *self, const char *entry)
{
return tfind(entry, &self->entries, str_compare) != NULL;
}
Elf_Scn *elf_section_by_name(Elf *elf, GElf_Ehdr *ep,
GElf_Shdr *shp, const char *name)
{
Elf_Scn *sec = NULL;
while ((sec = elf_nextscn(elf, sec)) != NULL) {
char *str;
gelf_getshdr(sec, shp);
str = elf_strptr(elf, ep->e_shstrndx, shp->sh_name);
if (!strcmp(name, str))
break;
}
return sec;
}

View File

@ -13,6 +13,8 @@
#include <stdbool.h>
#include <stddef.h>
#include <elf.h>
#include <gelf.h>
#ifndef __unused
#define __unused __attribute__ ((unused))
@ -55,4 +57,7 @@ int strlist__has_entry(const struct strlist *self, const char *entry);
void *zalloc(const size_t size);
Elf_Scn *elf_section_by_name(Elf *elf, GElf_Ehdr *ep,
GElf_Shdr *shp, const char *name);
#endif /* _DUTIL_H_ */