-#define rioWrite(rio,buf,len) ((rio)->write((rio),(buf),(len)))
-#define rioRead(rio,buf,len) ((rio)->read((rio),(buf),(len)))
+/* The following functions are our interface with the stream. They'll call the
+ * actual implementation of read / write / tell, and will update the checksum
+ * if needed. */
+
+static inline size_t rioWrite(rio *r, const void *buf, size_t len) {
+ if (r->update_cksum) r->update_cksum(r,buf,len);
+ return r->write(r,buf,len);
+}
+
+static inline size_t rioRead(rio *r, void *buf, size_t len) {
+ if (r->read(r,buf,len) == 1) {
+ if (r->update_cksum) r->update_cksum(r,buf,len);
+ return 1;
+ }
+ return 0;
+}