Add elfu_count{Section,PHDR}s
authornorly <ny-git@enpas.org>
Fri, 22 Feb 2013 16:58:14 +0000 (16:58 +0000)
committernorly <ny-git@enpas.org>
Fri, 22 Feb 2013 17:01:08 +0000 (17:01 +0000)
include/libelfu/model.h
src/model/count.c [new file with mode: 0644]

index aaf754f06a4c6b288ac98609f421443afa7fb8ce..1b5f6b6d5e8897729e111dedcc47d99edfe6b7c1 100644 (file)
@@ -43,6 +43,9 @@ typedef struct {
 
 
 
+size_t elfu_countSections(ElfuElf *me);
+size_t elfu_countPHDRs(ElfuElf *me);
+
 ElfuPhdr* elfu_modelFromPhdr(GElf_Phdr *phdr);
 ElfuScn* elfu_modelFromSection(Elf_Scn *scn);
 ElfuElf* elfu_modelFromElf(Elf *e);
diff --git a/src/model/count.c b/src/model/count.c
new file mode 100644 (file)
index 0000000..02f6a33
--- /dev/null
@@ -0,0 +1,33 @@
+#include <sys/types.h>
+#include <libelfu/libelfu.h>
+
+
+
+size_t elfu_countSections(ElfuElf *me)
+{
+  ElfuScn *ms;
+  size_t i = 0;
+
+  for (ms = me->scnList.cqh_first;
+        ms != (void *)&me->scnList;
+        ms = ms->elem.cqe_next) {
+    i++;
+  }
+
+  return i;
+}
+
+
+size_t elfu_countPHDRs(ElfuElf *me)
+{
+  ElfuPhdr *mp;
+  size_t i = 0;
+
+  for (mp = me->phdrList.cqh_first;
+        mp != (void *)&me->phdrList;
+        mp = mp->elem.cqe_next) {
+    i++;
+  }
+
+  return i;
+}