X-Git-Url: https://git.enpas.org/?a=blobdiff_plain;f=src%2Flibelfu%2Fmodel%2Fsection.c;fp=src%2Flibelfu%2Fmodel%2Fsection.c;h=74fbc3acb19ece9fc26932accb5a25b81cd8333e;hb=13b621d944766f19db762c0fd79e359e824a5f83;hp=9ef6fd8f342d89858f52326cbd399ddab83b82ec;hpb=c76af00e00b540ce7ddbc44d145bc2e70927a799;p=centaur.git diff --git a/src/libelfu/model/section.c b/src/libelfu/model/section.c index 9ef6fd8..74fbc3a 100644 --- a/src/libelfu/model/section.c +++ b/src/libelfu/model/section.c @@ -198,6 +198,30 @@ ElfuScn** elfu_mScnSortedByOffset(ElfuElf *me, size_t *count) +int elfu_mScnAppendData(ElfuScn *ms, void *buf, size_t len) +{ + char *newbuf; + + assert(ms); + assert(ms->shdr.sh_type != SHT_NOBITS); + assert(ms->databuf); + + newbuf = realloc(ms->databuf, ms->shdr.sh_size + len); + if (!newbuf) { + ELFU_WARN("elfu_mScnAppendData: malloc() failed for newbuf.\n"); + return -1; + } + + ms->databuf = newbuf; + memcpy(newbuf + ms->shdr.sh_size, buf, len); + ms->shdr.sh_size += len; + assert(ms->shdr.sh_size == ms->shdr.sh_size); + + return 0; +} + + + /* * Allocation, destruction */