diff options
author | midipix <writeonce@midipix.org> | 2018-08-03 23:16:42 +0000 |
---|---|---|
committer | midipix <writeonce@midipix.org> | 2018-08-03 21:13:31 -0400 |
commit | 2f4c03923b250a3bbf96188ceb91979841a95e91 (patch) | |
tree | 0b0a3fe3c47081345b72e9d7caa25b834c1cfbe9 /src/archive | |
parent | 1c93c26f73c2e8746defed21d22d83d08ac16eaf (diff) | |
download | mdso-2f4c03923b250a3bbf96188ceb91979841a95e91.tar.bz2 mdso-2f4c03923b250a3bbf96188ceb91979841a95e91.tar.xz |
library interfaces: archive generation: simplify, re-implement with mmap.
Diffstat (limited to 'src/archive')
-rw-r--r-- | src/archive/mdso_argen_common.c | 46 |
1 files changed, 21 insertions, 25 deletions
diff --git a/src/archive/mdso_argen_common.c b/src/archive/mdso_argen_common.c index 62cca47..9cd80d6 100644 --- a/src/archive/mdso_argen_common.c +++ b/src/archive/mdso_argen_common.c @@ -8,6 +8,7 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <sys/mman.h> #include <mdso/mdso.h> #include "mdso_errinfo_impl.h" @@ -50,7 +51,6 @@ int mdso_argen_common( const struct mdso_driver_ctx * dctx, const char ** symv, const int * stype, - FILE * fout, struct mdso_object * vobj) { int ret; @@ -63,6 +63,7 @@ int mdso_argen_common( uint32_t mapstrsnum; uint32_t mapstrslen; uint32_t symidx; + void * addr; unsigned char * ar; unsigned char * mark; unsigned char * idx; @@ -154,26 +155,26 @@ int mdso_argen_common( objlen |= 15; objlen ^= 15; - if (vobj && vobj->addr && (vobj->size < objlen)) + if (vobj->addr && (vobj->size < objlen)) return MDSO_BUFFER_ERROR(dctx); - if (vobj && !vobj->addr) { - vobj->size = objlen; + if ((addr = vobj->addr)) { + (void)0; + + } else { + vobj->size = objlen; vobj->mapstrslen = mapstrslen; vobj->mapstrsnum = mapstrsnum; - return 0; - } - - if (vobj) - ar = (unsigned char *)vobj->addr; - else if (!(ar = calloc(1,objlen))) { - if (aobj != sobj) - free(aobj); + if (!vobj->name) + return 0; - return MDSO_SYSTEM_ERROR(dctx); + else if (mdso_create_archive(dctx,vobj) < 0) + return MDSO_NESTED_ERROR(dctx); } + ar = (unsigned char *)vobj->addr; + /* archive signature */ memcpy(ar,"!<arch>\n",8); mark = &ar[8]; @@ -274,23 +275,18 @@ int mdso_argen_common( if (aobj != sobj) free(aobj); - if (!vobj) - free(ar); - return ret; } - /* tada */ - if (fout) - ret = fwrite(ar,objlen,1,fout); - + /* aobj */ if (aobj != sobj) free(aobj); - if (!vobj) - free(ar); + /* fs object unmap */ + if (!addr) + munmap(vobj->addr,vobj->size); + + /* tada */ + return 0; - return (ret == 0) - ? MDSO_FILE_ERROR(dctx) - : 0; } |