OSDN Git Service

* src/prototypes.h: updated.
authorarai <arai@6a8cc165-1e22-0410-a132-eb4e3f353aba>
Sun, 27 Jul 2003 08:37:33 +0000 (08:37 +0000)
committerarai <arai@6a8cc165-1e22-0410-a132-eb4e3f353aba>
Sun, 27 Jul 2003 08:37:33 +0000 (08:37 +0000)
* src/lha.h (exit): defined as lha_exit().

* src/lharc.c (init_variable): discard a variable
`remove_temporary_at_error'.
(fatal_error): ditto.
(cleanup): newly added.
(interrupt): call cleanup().
(lha_exit): newly added; cleanup temporary files always.

* src/lhadd.c (add_one): discard a variable
`remove_temporary_at_error'.

git-svn-id: svn+ssh://svn.sourceforge.jp/svnroot/lha/lha/trunk@758 6a8cc165-1e22-0410-a132-eb4e3f353aba

src/lha.h
src/lhadd.c
src/lharc.c
src/prototypes.h

index 099f34a..4416154 100644 (file)
--- a/src/lha.h
+++ b/src/lha.h
@@ -203,6 +203,8 @@ int fnmatch(const char *pattern, const char *string, int flags);
 
 #include "lha_macro.h"
 
+#define exit(n) lha_exit(n)
+
 struct encode_option {
 #if defined(__STDC__) || defined(AIX)
     void            (*output) ();
index 50b1fb8..9b9177c 100644 (file)
@@ -259,7 +259,6 @@ build_temporary_file()
     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);
@@ -340,8 +339,6 @@ temporary_to_new_archive_file(new_archive_size)
 
     recover_archive_when_interrupt = FALSE;
     unlink(temporary_name);
-
-    remove_temporary_at_error = FALSE;
 }
 
 /* ------------------------------------------------------------------------ */
index 8e17b3a..3a226fd 100644 (file)
@@ -86,7 +86,6 @@ init_variable()     /* Added N.Watazaki */
     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;
@@ -691,31 +690,37 @@ fatal_error(fmt, va_alist)
     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);
@@ -1319,3 +1324,13 @@ copy_old_one(oafp, nafp, hdr)
         copyfile(oafp, nafp, hdr->header_size + hdr->packed_size, 0, 0);
     }
 }
+
+#undef exit
+
+void
+lha_exit(status)
+    int status;
+{
+    cleanup();
+    exit(status);
+}
index 0ef1bc2..a87462a 100644 (file)
@@ -74,7 +74,9 @@ void message P_((char *fmt, ...));
 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));