LOAD PHDRs at top level, others as children. mPhdrForall().
[centaur.git] / src / libelfu / modelops / clone.c
1 #include <assert.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <libelfu/libelfu.h>
5
6 ElfuScn* elfu_mCloneScn(ElfuScn *ms)
7 {
8   ElfuScn *newscn;
9
10   assert(ms);
11
12   newscn = elfu_mScnAlloc();
13   if (!newscn) {
14     ELFU_WARN("elfu_nCloneScn: Could not allocate memory for new ElfuScn.\n");
15     return NULL;
16   }
17
18   newscn->shdr = ms->shdr;
19
20   if (ms->databuf) {
21     void *newbuf = malloc(ms->shdr.sh_size);
22     if (!newbuf) {
23       ELFU_WARN("elfu_nCloneScn: Could not allocate memory for new data buffer.\n");
24       free(newscn);
25       return NULL;
26     }
27
28     memcpy(newbuf, ms->databuf, ms->shdr.sh_size);
29     newscn->databuf = newbuf;
30   }
31
32   newscn->oldptr = ms;
33
34   return newscn;
35 }