summaryrefslogtreecommitdiffhomepage
path: root/src/logic/slbt_exec_ctx.c
diff options
context:
space:
mode:
authormidipix <writeonce@midipix.org>2016-04-02 11:42:02 -0400
committermidipix <writeonce@midipix.org>2016-04-02 11:42:02 -0400
commite7ddb294b84a2f012019d11f9fa5fad90dc304e5 (patch)
tree09ecd90947d59864f08c4f79dbb245d935f321fa /src/logic/slbt_exec_ctx.c
parent54d0a583ef6f40697f860b85c6d01b2540217f20 (diff)
downloadslibtool-e7ddb294b84a2f012019d11f9fa5fad90dc304e5.tar.bz2
slibtool-e7ddb294b84a2f012019d11f9fa5fad90dc304e5.tar.xz
slbt_reset_arguments(): initial implementation and integration.
Diffstat (limited to 'src/logic/slbt_exec_ctx.c')
-rw-r--r--src/logic/slbt_exec_ctx.c32
1 files changed, 30 insertions, 2 deletions
diff --git a/src/logic/slbt_exec_ctx.c b/src/logic/slbt_exec_ctx.c
index 1fbcca3..3eec822 100644
--- a/src/logic/slbt_exec_ctx.c
+++ b/src/logic/slbt_exec_ctx.c
@@ -16,6 +16,8 @@
struct slbt_exec_ctx_impl {
int argc;
char * args;
+ char * shadow;
+ size_t size;
struct slbt_exec_ctx ctx;
char * vbuffer[];
};
@@ -57,8 +59,10 @@ static struct slbt_exec_ctx_impl * slbt_exec_ctx_alloc(
{
struct slbt_exec_ctx_impl * ictx;
size_t size;
+ size_t vsize;
int argc;
char * args;
+ char * shadow;
char * csrc;
char ** parg;
@@ -102,16 +106,25 @@ static struct slbt_exec_ctx_impl * slbt_exec_ctx_alloc(
if (!(args = malloc(size)))
return 0;
- size = sizeof(*ictx) + (2*(argc+1)+SLBT_ARGV_SPARE_PTRS)*sizeof(char *);
+ if (!(shadow = malloc(size))) {
+ free(args);
+ return 0;
+ }
+
+ vsize = sizeof(*ictx) + (2*(argc+1)+SLBT_ARGV_SPARE_PTRS)*sizeof(char *);
- if (!(ictx = calloc(1,size))) {
+ if (!(ictx = calloc(1,vsize))) {
free(args);
+ free(shadow);
return 0;
}
ictx->args = args;
ictx->argc = argc;
+ ictx->size = size;
+ ictx->shadow = shadow;
+
ictx->ctx.csrc = csrc;
return ictx;
@@ -269,6 +282,9 @@ int slbt_get_exec_ctx(
+ sizeof('\0');
}
+ /* argument strings shadow copy */
+ memcpy(ictx->shadow,ictx->args,ictx->size);
+
*ectx = &ictx->ctx;
return 0;
}
@@ -279,6 +295,7 @@ static int slbt_free_exec_ctx_impl(
int status)
{
free(ictx->args);
+ free(ictx->shadow);
free (ictx);
return status;
}
@@ -297,6 +314,17 @@ void slbt_free_exec_ctx(struct slbt_exec_ctx * ctx)
}
+void slbt_reset_arguments(struct slbt_exec_ctx * ectx)
+{
+ struct slbt_exec_ctx_impl * ictx;
+ uintptr_t addr;
+
+ addr = (uintptr_t)ectx - offsetof(struct slbt_exec_ctx_impl,ctx);
+ ictx = (struct slbt_exec_ctx_impl *)addr;
+ memcpy(ictx->args,ictx->shadow,ictx->size);
+}
+
+
void slbt_reset_placeholders(struct slbt_exec_ctx * ectx)
{
*ectx->dpic = "-USLIBTOOL_PLACEHOLDER_DPIC";