Blame SOURCES/hunspell.rhbz759647.patch

5358ff
Index: src/tools/hunspell.cxx
5358ff
===================================================================
5358ff
RCS file: /cvsroot/hunspell/hunspell/src/tools/hunspell.cxx,v
5358ff
retrieving revision 1.28
5358ff
diff -u -r1.28 hunspell.cxx
5358ff
--- src/tools/hunspell.cxx	21 Jan 2011 17:30:41 -0000	1.28
5358ff
+++ src/tools/hunspell.cxx	6 Dec 2011 22:44:15 -0000
5358ff
@@ -128,8 +128,6 @@
5358ff
 #define readline scanline
5358ff
 #endif
5358ff
 
5358ff
-#define TEMPNAME "hunSPELL.bak"
5358ff
-
5358ff
 extern char * mystrdup(const char * s);
5358ff
 
5358ff
 // file formats:
5358ff
@@ -1316,14 +1314,12 @@
5358ff
     char * extension = basename(filename, '.');
5358ff
     parser = get_parser(format, extension, pMS[0]);
5358ff
 
5358ff
-    char * tempname = (char *) malloc(strlen(filename) + strlen(TEMPNAME) + 1);
5358ff
-    strcpy(tempname, filename);
5358ff
-    strcpy(basename(tempname, DIRSEPCH), TEMPNAME);
5358ff
-    
5358ff
-    FILE *tempfile;
5358ff
+   
5358ff
+    FILE *tempfile = tmpfile();
5358ff
 
5358ff
-    if (!(tempfile = fopen(tempname, "w"))) {
5358ff
-        fprintf(stderr, gettext("Can't create tempfile %s.\n"), tempname);
5358ff
+    if (!tempfile)
5358ff
+    {
5358ff
+        perror(gettext("Can't create tempfile"));
5358ff
         endwin();
5358ff
         exit(1);
5358ff
     }
5358ff
@@ -1337,7 +1333,7 @@
5358ff
 		    case -1: {
5358ff
 			clear();
5358ff
 			refresh();
5358ff
-			unlink(tempname);
5358ff
+			fclose(tempfile); //automatically deleted when closed
5358ff
 			endwin();
5358ff
 			exit(0);
5358ff
 		    }
5358ff
@@ -1350,15 +1346,22 @@
5358ff
 	    }
5358ff
 	}
5358ff
 	fclose(text);
5358ff
-	fclose(tempfile);
5358ff
 	delete parser;
5358ff
 
5358ff
-	if (! modified) {
5358ff
-	    unlink(tempname);
5358ff
-	} else {
5358ff
-            rename(tempname, filename);
5358ff
+	if (modified) {
5358ff
+		rewind(tempfile);
5358ff
+		text = fopen(filename, "wb");
5358ff
+
5358ff
+		size_t n;
5358ff
+		while ((n = fread(buf, 1, MAXLNLEN, tempfile)) > 0)
5358ff
+		{
5358ff
+			if (fwrite(buf, 1, n, text) != n)
5358ff
+				perror("write failed");
5358ff
+		}
5358ff
+
5358ff
+		fclose(text);
5358ff
 	}
5358ff
-        free(tempname);
5358ff
+	fclose(tempfile); //automatically deleted when closed
5358ff
 }
5358ff
 
5358ff
 #endif