+void move_pos_slow(struct stream_pos *pos, size_t offset);
+
+static inline
+void init_pos(struct stream_pos *pos, int fd)
+{
+ pos->fd = fd;
+ pos->mmap_offset = 0;
+ pos->packet_size = 0;
+ pos->content_size = 0;
+ pos->base = NULL;
+ pos->offset = 0;
+ pos->dummy = false;
+}
+
+/*
+ * move_pos - move position of a relative bit offset
+ *
+ * TODO: allow larger files by updating base too.
+ */
+static inline
+void move_pos(struct stream_pos *pos, size_t offset)
+{
+ if (pos->fd >= 0 && pos->offset + offset >= pos->content_size)
+ move_pos_slow(pos, offset);
+ else
+ pos->offset += offset;
+}
+
+/*
+ * align_pos - align position on a bit offset (> 0)
+ *
+ * TODO: allow larger files by updating base too.
+ */
+static inline
+void align_pos(struct stream_pos *pos, size_t offset)
+{
+ pos->offset += offset_align(pos->offset, offset);
+}
+
+static inline
+void copy_pos(struct stream_pos *dest, struct stream_pos *src)
+{
+ memcpy(dest, src, sizeof(struct stream_pos));
+}
+
+static inline
+char *get_pos_addr(struct stream_pos *pos)
+{
+ /* Only makes sense to get the address after aligning on CHAR_BIT */
+ assert(!(pos->offset % CHAR_BIT));
+ return pos->base + (pos->offset / CHAR_BIT);
+}
+