summaryrefslogtreecommitdiffhomepage
path: root/src/archive/mdso_argen_common.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/archive/mdso_argen_common.c')
-rw-r--r--src/archive/mdso_argen_common.c46
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;
}