+ return rf;
+
+error:
+ unblock_fatal_signals ();
+ free_replace_file (rf);
+ *fp = NULL;
+ if (tmp_name != NULL)
+ *tmp_name = NULL;
+ return NULL;
+}
+
+bool
+replace_file_commit (struct replace_file *rf)
+{
+ bool ok = true;
+
+ if (rf->file_name != NULL)
+ {
+ int save_errno;
+
+ block_fatal_signals ();
+ ok = rename (rf->tmp_name, rf->file_name) == 0;
+ save_errno = errno;
+ ll_remove (&rf->ll);
+ unblock_fatal_signals ();
+
+ if (!ok)
+ msg (ME, _("Replacing %s by %s: %s."),
+ rf->tmp_name, rf->file_name, strerror (save_errno));
+ }
+ else
+ {
+ /* Special file: no temporary file to rename. */
+ }
+ free_replace_file (rf);
+
+ return ok;
+}
+
+bool
+replace_file_abort (struct replace_file *rf)
+{
+ bool ok = true;
+
+ if (rf->file_name != NULL)
+ {
+ int save_errno;
+
+ block_fatal_signals ();
+ ok = unlink (rf->tmp_name) == 0;
+ save_errno = errno;
+ ll_remove (&rf->ll);
+ unblock_fatal_signals ();
+
+ if (!ok)
+ msg (ME, _("Removing %s: %s."), rf->tmp_name, strerror (save_errno));
+ }
+ else
+ {
+ /* Special file: no temporary file to unlink. */
+ }
+ free_replace_file (rf);
+
+ return ok;
+}
+
+static void
+free_replace_file (struct replace_file *rf)
+{
+ free (rf->file_name);
+ free (rf->tmp_name);
+ free (rf);
+}
+
+static void
+unlink_replace_files (void)
+{
+ struct replace_file *rf;
+
+ block_fatal_signals ();
+ ll_for_each (rf, struct replace_file, ll, &all_files)
+ {
+ /* We don't free_replace_file(RF) because calling free is unsafe
+ from an asynchronous signal handler. */
+ unlink (rf->tmp_name);
+ fflush (stdout);
+ }
+ unblock_fatal_signals ();
+}