Do not insert STRTAB sections explicitly
[centaur.git] / src / model / 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 = malloc(sizeof(ElfuScn));
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   newscn->data = ms->data;
20   if (ms->data.d_buf) {
21     void *newbuf = malloc(ms->data.d_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->data.d_buf, ms->data.d_size);
29     newscn->data.d_buf = newbuf;
30   }
31
32   newscn->linkptr = NULL;
33   newscn->infoptr = NULL;
34
35   newscn->oldptr = ms;
36
37   ms->symtab = NULL;
38   ms->reltab = NULL;
39
40   return newscn;
41 }