--- Src/hist.c 1 Oct 2004 19:48:53 -0000 1.54 +++ Src/hist.c 17 Oct 2004 19:44:20 -0000 @@ -2005,7 +2005,7 @@ readhistfile(char *fn, int err, int read void savehistfile(char *fn, int err, int writeflags) { - char *t, *start = NULL; + char *t, *tmpfile, *start = NULL; FILE *out; Histent he; zlong xcurhist = curhist - !!(histactive & HA_ACTIVE); @@ -2042,11 +2042,17 @@ savehistfile(char *fn, int err, int writ extended_history = 1; } if (writeflags & HFILE_APPEND) { + tmpfile = NULL; out = fdopen(open(unmeta(fn), O_CREAT | O_WRONLY | O_APPEND | O_NOCTTY, 0600), "a"); } else { - out = fdopen(open(unmeta(fn), + char *fnu = unmeta(fn); + int len = strlen(fnu); + tmpfile = zalloc(len + 10 + 1); + sprintf(tmpfile, "%s.%ld", fnu, (long)mypid); + unlink(tmpfile); + out = fdopen(open(tmpfile, O_CREAT | O_WRONLY | O_TRUNC | O_NOCTTY, 0600), "w"); } if (out) { @@ -2092,6 +2098,10 @@ savehistfile(char *fn, int err, int writ lasthist.text = ztrdup(start); } fclose(out); + if (tmpfile) { + rename(tmpfile, unmeta(fn)); + free(tmpfile); + } if (writeflags & HFILE_SKIPOLD && !(writeflags & (HFILE_FAST | HFILE_NO_REWRITE))) {