+/* Internal function: ensure that an fseek() is called on a file pointer in
+ between reading and writing operations, and vice versa. This will only come up
+ for ReadWrite or WriteAppend files. */
+static void
+ensure_file_operation(strid_t str, glui32 op)
+{
+ if(str->lastop != 0 && str->lastop != op)
+ {
+ long pos = ftell(str->file_pointer);
+ if(pos == -1)
+ WARNING_S("ftell() failed", g_strerror(errno));
+ if(fseek(str->file_pointer, pos, SEEK_SET) != 0)
+ WARNING_S("fseek() failed", g_strerror(errno));
+ }
+ str->lastop = op; /* Not 0, because we are about to do the operation anyway */
+}
+