OSDN Git Service

* src/lha.h: correct usage of mkstemp().
authorarai <arai@6a8cc165-1e22-0410-a132-eb4e3f353aba>
Sun, 19 May 2002 20:19:40 +0000 (20:19 +0000)
committerarai <arai@6a8cc165-1e22-0410-a132-eb4e3f353aba>
Sun, 19 May 2002 20:19:40 +0000 (20:19 +0000)
On MinGW, opened file cannot be removed.

* src/lhadd.c (build_temporary_file): ditto.

* src/lharc.c (fatal_error): ditto.

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

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

index 6bb3f0d..ccd8ea0 100644 (file)
--- a/src/lha.h
+++ b/src/lha.h
@@ -191,7 +191,7 @@ EXTERN long         reading_size;
 EXTERN unsigned int n_max;
 
 /* lhadd.c */
-EXTERN int temporary_fd = -1;
+EXTERN int temporary_fd;
 
 /* ------------------------------------------------------------------------ */
 /*     Functions                                                                                                                               */
@@ -219,7 +219,7 @@ extern void         finish_sp();
 extern void            free_sp();
 extern void            cleaning_files();
 
-extern void            build_temporary_name();
+extern int             build_temporary_name();
 extern void            build_backup_file_name();
 extern void            build_standard_archive_name();
 
index 3f0981c..8b0ed40 100644 (file)
@@ -277,14 +277,13 @@ build_temporary_file()
 
     remove_temporary_at_error = TRUE;
     temporary_fd = build_temporary_name();
-    if (fd == -1)
+    if (temporary_fd == -1)
         fatal_error(temporary_name);
 
-    afp = fdopen(temporary_name, WRITE_BINARY);
+    afp = fdopen(temporary_fd, WRITE_BINARY);
     if (afp == NULL)
         fatal_error(temporary_name);
 
-
     return afp;
 }
 
index 4747ee6..69b594f 100644 (file)
@@ -126,6 +126,7 @@ init_variable()             /* Added N.Watazaki */
 
        extract_directory = NULL;
        xfilec = 257;
+    temporary_fd = -1;
 }
 
 /* ------------------------------------------------------------------------ */
@@ -931,10 +932,25 @@ build_temporary_name()
        strcpy((s ? s + 1 : temporary_name), "lhXXXXXX");
 #endif
 #ifdef HAVE_MKSTEMP
-       return mkstemp(temporary_name);
+    {
+        int old_umask, fd;
+
+        old_umask = umask(077);
+        fd = mkstemp(temporary_name);
+        umask(old_umask);
+        return fd;
+    }
 #else
-       mktemp(temporary_name);
-    return open(temporary_name, O_CREAT|O_EXCL|O_RDWR|O_BINARY, 0600);
+    {
+        int flags;
+        mktemp(temporary_name);
+
+        flags = O_CREAT|O_EXCL|O_RDWR;
+#ifdef O_BINARY
+        flags |= O_BINARY;
+#endif
+        return open(temporary_name, flags, 0600);
+    }
 #endif
 }