uint64_t id = 0;
int ret;
+ ctf_pos_get_event(pos);
+
if (pos->offset == EOF)
return EOF;
+ assert(pos->offset < pos->content_size);
/* Read event header */
if (stream->stream_event_header) {
assert(off >= 0);
pos->offset = 0;
} else {
+ read_next_packet:
switch (whence) {
case SEEK_CUR:
+ if (pos->offset == EOF)
+ return;
/* The reader will expect us to skip padding */
assert(pos->offset + offset == pos->content_size);
++pos->cur_index;
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 if (index->data_offset == index->content_size) {
+ /* empty packet */
+ pos->offset = index->data_offset;
+ offset = 0;
+ goto read_next_packet;
} else {
pos->offset = EOF;
return;
return;
if (pos->fd >= 0) {
- if (((pos->prot == PROT_READ)
- && (pos->offset + bit_offset >= pos->content_size))
- || ((pos->prot == PROT_WRITE)
- && (pos->offset + bit_offset >= pos->packet_size))) {
+ /*
+ * PROT_READ ctf_move_pos_slow is called from within
+ * ctf_pos_get_event so end of packet does not change
+ * the packet context on for the last event of the
+ * packet.
+ */
+ if ((pos->prot == PROT_WRITE)
+ && (pos->offset + bit_offset >= pos->packet_size)) {
printf_debug("ctf_move_pos_slow (before call): %zd\n",
pos->offset);
ctf_move_pos_slow(pos, bit_offset, SEEK_CUR);
return 1;
}
+/*
+ * Update the stream position for to the current event. This moves to
+ * the next packet if we are located at the end of the current packet.
+ */
+static inline
+void ctf_pos_get_event(struct ctf_stream_pos *pos)
+{
+ assert(pos->offset <= pos->content_size);
+ if (pos->offset == pos->content_size) {
+ printf_debug("ctf_move_pos_slow (before call): %zd\n",
+ pos->offset);
+ ctf_move_pos_slow(pos, 0, SEEK_CUR);
+ printf_debug("ctf_move_pos_slow (after call): %zd\n",
+ pos->offset);
+ }
+}
+
#endif /* _BABELTRACE_CTF_TYPES_H */