1 /* This file is part of centaur.
3 * centaur is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License 2 as
5 * published by the Free Software Foundation.
7 * centaur is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with centaur. If not, see <http://www.gnu.org/licenses/>.
19 #include <libelfu/libelfu.h>
23 * Allocation, destruction
26 ElfuElf* elfu_mElfAlloc()
30 me = malloc(sizeof(ElfuElf));
32 ELFU_WARN("mElfAlloc: malloc() failed for ElfuElf.\n");
36 memset(me, 0, sizeof(*me));
38 CIRCLEQ_INIT(&me->phdrList);
39 CIRCLEQ_INIT(&me->orphanScnList);
45 void elfu_mElfDestroy(ElfuElf* me)
49 if (!CIRCLEQ_EMPTY(&me->phdrList)) {
52 nextmp = CIRCLEQ_FIRST(&me->phdrList);
53 while ((void*)nextmp != (void*)&me->phdrList) {
54 ElfuPhdr *curmp = nextmp;
55 nextmp = CIRCLEQ_NEXT(curmp, elem);
56 CIRCLEQ_REMOVE(&me->phdrList, curmp, elem);
57 elfu_mPhdrDestroy(curmp);
61 if (!CIRCLEQ_EMPTY(&me->orphanScnList)) {
64 nextms = CIRCLEQ_FIRST(&me->orphanScnList);
65 while ((void*)nextms != (void*)&me->orphanScnList) {
66 ElfuScn *curms = nextms;
67 nextms = CIRCLEQ_NEXT(curms, elemChildScn);
68 CIRCLEQ_REMOVE(&me->orphanScnList, curms, elemChildScn);
69 elfu_mScnDestroy(curms);