+static uint32_t offset_next_write,
+ wrap_count;
+
+static i3_shmlog_header *header;
+static char *logbuffer,
+ *walk;
+
+static int check_for_wrap(void) {
+ if (wrap_count == header->wrap_count)
+ return 0;
+
+ /* The log wrapped. Print the remaining content and reset walk to the top
+ * of the log. */
+ wrap_count = header->wrap_count;
+ write(STDOUT_FILENO, walk, ((logbuffer + header->offset_last_wrap) - walk));
+ walk = logbuffer + sizeof(i3_shmlog_header);
+ return 1;
+}
+
+static void print_till_end(void) {
+ check_for_wrap();
+ int n = write(STDOUT_FILENO, walk, ((logbuffer + header->offset_next_write) - walk));
+ if (n > 0) {
+ walk += n;
+ }
+}
+