summaryrefslogtreecommitdiff
path: root/lib-src/update-game-score.c
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2013-08-04 09:56:56 -0700
committerPaul Eggert <eggert@cs.ucla.edu>2013-08-04 09:56:56 -0700
commite0fdb6943066032db294720915c3bd644bf2bcd1 (patch)
tree0aa420b81dc0187e2efec3ff4fe3cf046ad1c598 /lib-src/update-game-score.c
parent484ab23924d39b3e26d54074fd659633e1660ef4 (diff)
downloademacs-e0fdb6943066032db294720915c3bd644bf2bcd1.tar.gz
Fix some minor races in hosts lacking mkostemp.
Gnulib's emulation of mkostemp doesn't have races that Emacs's does. * configure.ac (mkostemp): Remove check for this function; gnulib does the check now. (mkstemp): Remove check for this no-longer-used function. * lib/mkostemp.c, lib/secure_getenv.c, lib/tempname.c, lib/tempname.h: * m4/mkostemp.m4, m4/secure_getenv.m4, m4/tempname.m4: New files, copied from Gnulib. * lib/gnulib.mk, m4/gnulib-comp.m4: Regenerate. * admin/merge-gnulib (GNULIB_MODULES): Add mkostemp. * lib-src/movemail.c (main): * lib-src/update-game-score.c (write_scores): Use mkostemp (which now works on all platforms, due to changes in the portability layer) rather than mktemp (which has a race) or mkstemp (which we no longer bother with). * src/callproc.c (create_temp_file): * src/filelock.c (create_lock_file): Assume mkostemp, since it's now provided by Gnulib. Fixes: debbugs:15015
Diffstat (limited to 'lib-src/update-game-score.c')
-rw-r--r--lib-src/update-game-score.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/lib-src/update-game-score.c b/lib-src/update-game-score.c
index ec8b4317770..1699e305c8d 100644
--- a/lib-src/update-game-score.c
+++ b/lib-src/update-game-score.c
@@ -383,6 +383,7 @@ sort_scores (struct score_entry *scores, int count, int reverse)
static int
write_scores (const char *filename, const struct score_entry *scores, int count)
{
+ int fd;
FILE *f;
int i;
char *tempfile = malloc (strlen (filename) + strlen (".tempXXXXXX") + 1);
@@ -390,12 +391,11 @@ write_scores (const char *filename, const struct score_entry *scores, int count)
return -1;
strcpy (tempfile, filename);
strcat (tempfile, ".tempXXXXXX");
-#ifdef HAVE_MKSTEMP
- if (mkstemp (tempfile) < 0
-#else
- if (mktemp (tempfile) != tempfile
-#endif
- || !(f = fopen (tempfile, "w")))
+ fd = mkostemp (tempfile, 0);
+ if (fd < 0)
+ return -1;
+ f = fdopen (fd, "w");
+ if (! f)
return -1;
for (i = 0; i < count; i++)
if (fprintf (f, "%ld %s %s\n", scores[i].score, scores[i].username,