lib-ucode: truncate pcap files
[project/udebug.git] / lib-ucode.c
index 8e042e3f99f36b8b4f97b2eae0ae0a3a573259d1..d50fd905c716ebe2b14585194d5e079412c5b093 100644 (file)
@@ -325,9 +325,10 @@ uc_udebug_pcap_file(uc_vm_t *vm, size_t nargs)
        uc_value_t *args = uc_fn_arg(1);
        int fd = -1;
 
-       if (ucv_type(file) == UC_STRING)
+       if (ucv_type(file) == UC_STRING) {
                fd = open(ucv_string_get(file), O_WRONLY | O_CREAT, 0644);
-       else if (!file)
+               ftruncate(fd, 0);
+       } else if (!file)
                fd = STDOUT_FILENO;
 
        return uc_debug_pcap_init(fd, args);