X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=plugins%2Flibctfcopytrace%2Fctfcopytrace.c;h=882ab85a27c0971a8b960930c287139d98ef8de9;hb=944eed39a1ec69fc7ba752aa1607aa97e80abfee;hp=0689ee380c8651261c65fdffd17da10d64ff5594;hpb=ab80adac56044ab951e76eb818c4ca1140d2a0a2;p=babeltrace.git diff --git a/plugins/libctfcopytrace/ctfcopytrace.c b/plugins/libctfcopytrace/ctfcopytrace.c index 0689ee38..882ab85a 100644 --- a/plugins/libctfcopytrace/ctfcopytrace.c +++ b/plugins/libctfcopytrace/ctfcopytrace.c @@ -538,7 +538,7 @@ struct bt_ctf_field *ctf_copy_packet_context(FILE *err, struct bt_ctf_field_type *struct_type = NULL, *writer_packet_context_type = NULL; struct bt_ctf_stream_class *writer_stream_class = NULL; struct bt_ctf_field *field = NULL; - struct bt_ctf_field_type *field_type; + struct bt_ctf_field_type *field_type = NULL; int nr_fields, i; packet_context = bt_ctf_packet_get_context(packet); @@ -833,6 +833,7 @@ enum bt_component_status ctf_copy_trace(FILE *err, struct bt_ctf_trace *trace, enum bt_component_status ret = BT_COMPONENT_STATUS_OK; int field_count, i, int_ret; struct bt_ctf_field_type *header_type = NULL; + enum bt_ctf_byte_order order; field_count = bt_ctf_trace_get_environment_field_count(trace); for (i = 0; i < field_count; i++) { @@ -870,19 +871,37 @@ enum bt_component_status ctf_copy_trace(FILE *err, struct bt_ctf_trace *trace, } } - header_type = bt_ctf_trace_get_packet_header_type(writer_trace); - if (!header_type) { + order = bt_ctf_trace_get_native_byte_order(trace); + if (order == BT_CTF_BYTE_ORDER_UNKNOWN) { 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; + /* + * 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) { + 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: