+ assert(rc);
+
+ /* Now, we have to try to sort out the journal so that it's
+ * truncated and positioned to where this abortively-written record
+ * started, with no buffered output and the error indicator clear.
+ *
+ * There seems to be no portable way to ensure the buffered unwritten
+ * output is discarded, so we close and reopen the stream.
+ */
+ fclose(rw->logfile);
+
+ rw->logfile= fopen(pathbuf_sfx(&rw->pbsome,".jrn"), "r+");
+ if (!rw->logfile) { failed= "fopen"; goto reset_fail; }
+
+ r= ftruncate(fileno(rw->logfile), recstart);
+ if (r) { failed= "ftruncate"; goto reset_fail; }
+
+ r= fseeko(rw->logfile, recstart, SEEK_SET);
+ if (r) { failed= "fseeko"; goto reset_fail; }
+
+ return rc;
+
+ reset_fail:
+ Tcl_AppendResult(ip, " (additionally, ", failed, " failed"
+ " in error recovery: ", strerror(errno), ")", (char*)0);
+ if (rw->logfile) { fclose(rw->logfile); rw->logfile= 0; }
+