Add CTF Writer implementation
[babeltrace.git] / formats / ctf / ctf.c
index bb94e52770e36641fd8107414229992426ec1e58..60d9c9f9459d159b7627c9e76927409eccd55272 100644 (file)
@@ -670,7 +670,7 @@ int ctf_fini_pos(struct ctf_stream_pos *pos)
 
 /*
  * for SEEK_CUR: go to next packet.
- * for SEEK_POS: go to packet numer (index).
+ * for SEEK_SET: go to packet numer (index).
  */
 void ctf_packet_seek(struct bt_stream_pos *stream_pos, size_t index, int whence)
 {
@@ -712,7 +712,7 @@ void ctf_packet_seek(struct bt_stream_pos *stream_pos, size_t index, int whence)
                switch (whence) {
                case SEEK_CUR:
                        /* The writer will add padding */
-                       pos->mmap_offset += WRITE_PACKET_LEN / CHAR_BIT;
+                       pos->mmap_offset += pos->packet_size / CHAR_BIT;
                        break;
                case SEEK_SET:
                        assert(index == 0);     /* only seek supported for now */
@@ -729,14 +729,6 @@ void ctf_packet_seek(struct bt_stream_pos *stream_pos, size_t index, int whence)
                pos->offset = 0;
        } else {
        read_next_packet:
-               if (pos->cur_index >= pos->packet_cycles_index->len) {
-                       pos->offset = EOF;
-                       return;
-               }
-               if (pos->cur_index >= pos->packet_real_index->len) {
-                       pos->offset = EOF;
-                       return;
-               }
                switch (whence) {
                case SEEK_CUR:
                {
@@ -745,6 +737,9 @@ void ctf_packet_seek(struct bt_stream_pos *stream_pos, size_t index, int whence)
                        if (pos->offset == EOF) {
                                return;
                        }
+                       assert(pos->cur_index < pos->packet_cycles_index->len);
+                       assert(pos->cur_index < pos->packet_real_index->len);
+
                        /* For printing discarded event count */
                        packet_index = &g_array_index(pos->packet_cycles_index,
                                        struct packet_index, pos->cur_index);
@@ -782,6 +777,10 @@ void ctf_packet_seek(struct bt_stream_pos *stream_pos, size_t index, int whence)
                        break;
                }
                case SEEK_SET:
+                       if (index >= pos->packet_cycles_index->len) {
+                               pos->offset = EOF;
+                               return;
+                       }
                        packet_index = &g_array_index(pos->packet_cycles_index,
                                        struct packet_index, index);
                        pos->last_events_discarded = packet_index->events_discarded;
This page took 0.025495 seconds and 4 git commands to generate.