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