signal(SIGHUP, interrupt);
#endif
- remove_temporary_at_error = TRUE;
temporary_fd = build_temporary_name();
if (temporary_fd == -1)
fatal_error("Cannot open temporary file \"%s\"", temporary_name);
recover_archive_when_interrupt = FALSE;
unlink(temporary_name);
-
- remove_temporary_at_error = FALSE;
}
/* ------------------------------------------------------------------------ */
delete_after_append = FALSE;
generic_format = FALSE;
- remove_temporary_at_error = FALSE;
recover_archive_when_interrupt = FALSE;
remove_extracting_file_when_interrupt = FALSE;
get_filename_from_stdin = FALSE;
else
fputs("\n", stderr);
- if (remove_temporary_at_error) {
- if (temporary_fd != -1)
- close(temporary_fd);
+ exit(1);
+}
+
+void
+cleanup()
+{
+ if (temporary_fd != -1) {
+ close(temporary_fd);
+ temporary_fd = -1;
unlink(temporary_name);
}
- exit(1);
+ if (recover_archive_when_interrupt) {
+ rename(backup_archive_name, archive_name);
+ recover_archive_when_interrupt = FALSE;
+ }
+ if (remove_extracting_file_when_interrupt) {
+ message("Removing: %s", writing_filename);
+ unlink(writing_filename);
+ remove_extracting_file_when_interrupt = FALSE;
+ }
}
-/* ------------------------------------------------------------------------ */
RETSIGTYPE
interrupt(signo)
int signo;
{
message("Interrupted");
- if (temporary_fd != -1)
- close(temporary_fd);
- unlink(temporary_name);
- if (recover_archive_when_interrupt)
- rename(backup_archive_name, archive_name);
- if (remove_extracting_file_when_interrupt) {
- message("Removing: %s", writing_filename);
- unlink(writing_filename);
- }
+ cleanup();
+
signal(SIGINT, SIG_DFL);
#ifdef SIGHUP
signal(SIGHUP, SIG_DFL);
copyfile(oafp, nafp, hdr->header_size + hdr->packed_size, 0, 0);
}
}
+
+#undef exit
+
+void
+lha_exit(status)
+ int status;
+{
+ cleanup();
+ exit(status);
+}
void warning P_((char *fmt, ...));
void error P_((char *fmt, ...));
void fatal_error P_((char *fmt, ...));
+void cleanup P_((void));
RETSIGTYPE interrupt P_((int signo));
+void lha_exit P_((int status));
void *xmalloc P_((size_t size));
void *xrealloc P_((void *old, size_t size));
char *xstrdup P_((char *str));