Object file injection, first part
[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
19
20   newscn->shdr = ms->shdr;
21   newscn->data = ms->data;
22   if (ms->data.d_buf) {
23     void *newbuf = malloc(ms->data.d_size);
24     if (!newbuf) {
25       ELFU_WARN("elfu_nCloneScn: Could not allocate memory for new data buffer.\n");
26       free(newscn);
27       return NULL;
28     }
29
30     memcpy(newbuf, ms->data.d_buf, ms->data.d_size);
31     newscn->data.d_buf = newbuf;
32   }
33
34   return newscn;
35 }