Fix copytrace: packet header is optional
[babeltrace.git] / plugins / libctfcopytrace / ctfcopytrace.c
index 99a332bebce9e8c3c6227c6599e12d08a6ca249e..882ab85a27c0971a8b960930c287139d98ef8de9 100644 (file)
@@ -878,26 +878,30 @@ enum bt_component_status ctf_copy_trace(FILE *err, struct bt_ctf_trace *trace,
                goto end;
        }
 
-       ret = bt_ctf_trace_set_native_byte_order(writer_trace, order);
-       if (ret) {
-               fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__, __LINE__);
-               ret = BT_COMPONENT_STATUS_ERROR;
-               goto end;
+       /*
+        * Only explicitly set the writer trace's native byte order if
+        * the original trace has a specific one. Otherwise leave what
+        * the CTF writer object chooses, which is the machine's native
+        * byte order.
+        */
+       if (order != BT_CTF_BYTE_ORDER_NONE) {
+               ret = bt_ctf_trace_set_native_byte_order(writer_trace, order);
+               if (ret) {
+                       fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__, __LINE__);
+                       ret = BT_COMPONENT_STATUS_ERROR;
+                       goto end;
+               }
        }
 
        header_type = bt_ctf_trace_get_packet_header_type(writer_trace);
-       if (!header_type) {
-               fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__, __LINE__);
-               ret = BT_COMPONENT_STATUS_ERROR;
-               goto end;
-       }
-
-       int_ret = bt_ctf_trace_set_packet_header_type(writer_trace, header_type);
-       BT_PUT(header_type);
-       if (int_ret < 0) {
-               fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__, __LINE__);
-               ret = BT_COMPONENT_STATUS_ERROR;
-               goto end;
+       if (header_type) {
+               int_ret = bt_ctf_trace_set_packet_header_type(writer_trace, header_type);
+               BT_PUT(header_type);
+               if (int_ret < 0) {
+                       fprintf(err, "[error] %s in %s:%d\n", __func__, __FILE__, __LINE__);
+                       ret = BT_COMPONENT_STATUS_ERROR;
+                       goto end;
+               }
        }
 
 end:
This page took 0.023473 seconds and 4 git commands to generate.