summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorJo-Philipp Wich <jo@mein.io>2021-05-10 16:28:49 +0200
committerJo-Philipp Wich <jo@mein.io>2021-05-10 16:31:50 +0200
commit0cb10c62a0d663fe42cebb4134e7cfcd3c461156 (patch)
tree51decb6c88de07fa9c8bb5d31491b47ff781d741
parenteb8a64d461851756e65093edf923bd534e86aae5 (diff)
vm: implement mechanism to change output file descriptor
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
-rw-r--r--lib.c4
-rw-r--r--types.h1
-rw-r--r--vm.c8
3 files changed, 8 insertions, 5 deletions
diff --git a/lib.c b/lib.c
index c1583f9..9d8241b 100644
--- a/lib.c
+++ b/lib.c
@@ -292,7 +292,7 @@ uc_print_common(uc_vm *vm, size_t nargs, FILE *fh)
static uc_value_t *
uc_print(uc_vm *vm, size_t nargs)
{
- return uc_print_common(vm, nargs, stdout);
+ return uc_print_common(vm, nargs, vm->output);
}
static uc_value_t *
@@ -1495,7 +1495,7 @@ uc_printf(uc_vm *vm, size_t nargs)
uc_printf_common(vm, nargs, buf);
- len = fwrite(buf->buf, 1, printbuf_length(buf), stdout);
+ len = fwrite(buf->buf, 1, printbuf_length(buf), vm->output);
printbuf_free(buf);
diff --git a/types.h b/types.h
index 518248b..3aaf8bc 100644
--- a/types.h
+++ b/types.h
@@ -259,6 +259,7 @@ struct uc_vm {
size_t spread_values;
uint8_t trace;
uc_stringbuf_t *strbuf;
+ FILE *output;
};
diff --git a/vm.c b/vm.c
index 25b146a..5b7b5e8 100644
--- a/vm.c
+++ b/vm.c
@@ -118,6 +118,8 @@ void uc_vm_init(uc_vm *vm, uc_parse_config *config)
vm->strbuf = NULL;
+ vm->output = stdout;
+
uc_vm_reset_stack(vm);
}
@@ -1896,12 +1898,12 @@ uc_vm_insn_print(uc_vm *vm, enum insn_type insn)
case UC_OBJECT:
case UC_ARRAY:
p = ucv_to_jsonstring(vm, v);
- fwrite(p, 1, strlen(p), stdout);
+ fwrite(p, 1, strlen(p), vm->output);
free(p);
break;
case UC_STRING:
- fwrite(ucv_string_get(v), 1, ucv_string_length(v), stdout);
+ fwrite(ucv_string_get(v), 1, ucv_string_length(v), vm->output);
break;
case UC_NULL:
@@ -1909,7 +1911,7 @@ uc_vm_insn_print(uc_vm *vm, enum insn_type insn)
default:
p = ucv_to_string(vm, v);
- fwrite(p, 1, strlen(p), stdout);
+ fwrite(p, 1, strlen(p), vm->output);
free(p);
}