X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=blobdiff_plain;f=formats%2Fctf%2Fctf.c;h=7120207ddb5a47dafeb50089b13f1c542563ea7e;hp=098b7eb15d7d4589880243ed7d0ecdc66c7b4152;hb=7eda6fc7537f70a15af83ad11cc3a8c549052028;hpb=01c76b246be85b5d9c8e99813950fb194c9f714f diff --git a/formats/ctf/ctf.c b/formats/ctf/ctf.c index 098b7eb1..7120207d 100644 --- a/formats/ctf/ctf.c +++ b/formats/ctf/ctf.c @@ -415,9 +415,9 @@ void ctf_move_pos_slow(struct ctf_stream_pos *pos, size_t offset, int whence) file_stream->parent.timestamp = index->timestamp_begin; pos->content_size = index->content_size; pos->packet_size = index->packet_size; - if (index->data_offset < index->content_size) + if (index->data_offset <= index->content_size) { pos->offset = 0; /* will read headers */ - else { + } else { pos->offset = EOF; return; } @@ -458,12 +458,13 @@ int packet_metadata(struct ctf_trace *td, FILE *fp) if (magic == TSDL_MAGIC) { ret = 1; td->byte_order = BYTE_ORDER; + CTF_TRACE_SET_FIELD(td, byte_order); } else if (magic == GUINT32_SWAP_LE_BE(TSDL_MAGIC)) { ret = 1; td->byte_order = (BYTE_ORDER == BIG_ENDIAN) ? LITTLE_ENDIAN : BIG_ENDIAN; + CTF_TRACE_SET_FIELD(td, byte_order); } - CTF_TRACE_SET_FIELD(td, byte_order); end: rewind(fp); return ret; @@ -611,6 +612,18 @@ int ctf_open_trace_metadata_read(struct ctf_trace *td) ret = ctf_open_trace_metadata_stream_read(td, &fp, &buf); if (ret) goto end_packet_read; + } else { + char buf[sizeof("/* TSDL")]; /* Includes \0 */ + ssize_t readlen; + + td->byte_order = BYTE_ORDER; + + /* Check text-only metadata header */ + buf[sizeof("/* TSDL") - 1] = '\0'; + readlen = fread(buf, sizeof("/* TSDL") - 1, 1, fp); + if (readlen < 1 || strcmp(buf, "/* TSDL") != 0) + fprintf(stdout, "[warning] Missing \"/* TSDL\" header for text-only metadata.\n"); + rewind(fp); } scanner = ctf_scanner_alloc(fp); @@ -639,7 +652,7 @@ int ctf_open_trace_metadata_read(struct ctf_trace *td) goto end; } ret = ctf_visitor_construct_metadata(stdout, 0, &scanner->ast->root, - td, BYTE_ORDER); + td, td->byte_order); if (ret) { fprintf(stdout, "[error] Error in CTF metadata constructor %d\n", ret); goto end;