X-Git-Url: http://git.efficios.com/?p=babeltrace.git;a=blobdiff_plain;f=formats%2Fctf%2Fctf.c;h=7120207ddb5a47dafeb50089b13f1c542563ea7e;hp=d685b6cd70f4b9ef9362747bb7fa8862a430f086;hb=7eda6fc7537f70a15af83ad11cc3a8c549052028;hpb=da75b0f7af646e4bd6a7cf3747c6a1402fc1967d diff --git a/formats/ctf/ctf.c b/formats/ctf/ctf.c index d685b6cd..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; @@ -612,7 +613,17 @@ int ctf_open_trace_metadata_read(struct ctf_trace *td) 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);