+#include <string.h>
+
+#include "lib/unaligned.h"
+
+/*
+ * Generic buffered I/O on a top of buffer swapping functions.
+ *
+ * Buffer layout when reading:
+ *
+ * +----------------+---------------------------+
+ * | read data | free space |
+ * +----------------+---------------------------+
+ * ^ ^ ^ ^
+ * buffer bptr bstop bufend
+ *
+ * After the last character is read, bptr == bstop and buffer refill
+ * is deferred to the next read attempt. This gives us an easy way
+ * how to implement bungetc().
+ *
+ * When writing:
+ *
+ * +----------------+---------------------------+
+ * | written data | free space |
+ * +----------------+---------------------------+
+ * ^ ^ ^
+ * buffer=bstop bptr bufend
+ */
+