aboutsummaryrefslogtreecommitdiffstats
path: root/lib-src
diff options
context:
space:
mode:
authorroot2013-08-12 12:27:22 +0200
committerroot2013-08-12 12:27:22 +0200
commitc39e73975f7371a6458cd63967d39ba77a1e871a (patch)
tree145fb3d8489ecd65ac6b1887e17a204bff751286 /lib-src
parent2427b15992fe47646a2bf2b55891f1e482dedaa0 (diff)
parent6edea0a595d292c4d3f1a7e862195be07c874e40 (diff)
downloademacs-c39e73975f7371a6458cd63967d39ba77a1e871a.tar.gz
emacs-c39e73975f7371a6458cd63967d39ba77a1e871a.zip
merge from trunk
Conflicts: src/Makefile.in
Diffstat (limited to 'lib-src')
-rw-r--r--lib-src/ChangeLog43
-rw-r--r--lib-src/Makefile.in10
-rw-r--r--lib-src/makefile.w32-in1
-rw-r--r--lib-src/movemail.c17
-rw-r--r--lib-src/ntlib.c69
-rw-r--r--lib-src/ntlib.h5
-rw-r--r--lib-src/update-game-score.c56
-rw-r--r--lib-src/update-game-score.exe.manifest10
8 files changed, 164 insertions, 47 deletions
diff --git a/lib-src/ChangeLog b/lib-src/ChangeLog
index f41c23df5d2..53d66ba1e37 100644
--- a/lib-src/ChangeLog
+++ b/lib-src/ChangeLog
@@ -1,3 +1,46 @@
12013-08-10 Eli Zaretskii <eliz@gnu.org>
2
3 * update-game-score.exe.manifest: New file.
4
5 * Makefile.in (UPDATE_MANIFEST): New variable.
6 (SCRIPTS): Add $(UPDATE_MANIFEST).
7
82013-08-05 Stefan Monnier <monnier@iro.umontreal.ca>
9
10 * makefile.w32-in (lisp2): Add nadvice.elc.
11
122013-08-05 Eli Zaretskii <eliz@gnu.org>
13
14 * update-game-score.c (read_score): Try reading a character before
15 probing the stream for EOF. Initialize score->score to zero,
16 before reading and accumulating the score.
17 (read_scores): Fix logic that determines which value to return.
18 Close the input stream when finished reading the scores (avoids
19 failures in overwriting the file with a new one on MS-Windows,
20 since a file that is open cannot be deleted).
21
22 * ntlib.h (rename): Don't undefine.
23
24 * ntlib.c (sys_rename): New function, needed for
25 update-game-score.
26
272013-08-04 Eli Zaretskii <eliz@gnu.org>
28
29 * ntlib.h: Include fcntl.h.
30 (mkostemp): Declare prototype.
31 (mktemp): Don't redefine.
32
33 * ntlib.c (mkostemp): New function. (Bug#15015)
34
352013-08-04 Paul Eggert <eggert@cs.ucla.edu>
36
37 Fix some minor races in hosts lacking mkostemp (Bug#15015).
38 * movemail.c (main):
39 * update-game-score.c (write_scores):
40 Use mkostemp (which now works on all platforms, due to changes
41 in the portability layer) rather than mktemp (which has a race)
42 or mkstemp (which we no longer bother with).
43
12013-07-10 Paul Eggert <eggert@cs.ucla.edu> 442013-07-10 Paul Eggert <eggert@cs.ucla.edu>
2 45
3 Port to C89. 46 Port to C89.
diff --git a/lib-src/Makefile.in b/lib-src/Makefile.in
index 2e0e2818767..fe1900a2a40 100644
--- a/lib-src/Makefile.in
+++ b/lib-src/Makefile.in
@@ -1,6 +1,7 @@
1# Makefile for lib-src subdirectory in GNU Emacs. 1### @configure_input@
2# Copyright (C) 1985, 1987-1988, 1993-1994, 2001-2013 Free Software 2
3# Foundation, Inc. 3# Copyright (C) 1985, 1987-1988, 1993-1994, 2001-2013
4# Free Software Foundation, Inc.
4 5
5# This file is part of GNU Emacs. 6# This file is part of GNU Emacs.
6 7
@@ -39,6 +40,7 @@ C_SWITCH_MACHINE=@C_SWITCH_MACHINE@
39PROFILING_CFLAGS = @PROFILING_CFLAGS@ 40PROFILING_CFLAGS = @PROFILING_CFLAGS@
40WARN_CFLAGS = @WARN_CFLAGS@ 41WARN_CFLAGS = @WARN_CFLAGS@
41WERROR_CFLAGS = @WERROR_CFLAGS@ 42WERROR_CFLAGS = @WERROR_CFLAGS@
43UPDATE_MANIFEST = @UPDATE_MANIFEST@
42 44
43# Program name transformation. 45# Program name transformation.
44TRANSFORM = @program_transform_name@ 46TRANSFORM = @program_transform_name@
@@ -131,7 +133,7 @@ DONT_INSTALL= test-distrib${EXEEXT} make-docfile${EXEEXT}
131 133
132# Like UTILITIES, but they're not system-dependent, and should not be 134# Like UTILITIES, but they're not system-dependent, and should not be
133# deleted by the distclean target. 135# deleted by the distclean target.
134SCRIPTS= rcs2log 136SCRIPTS= rcs2log $(UPDATE_MANIFEST)
135 137
136# All files that are created by the linker, i.e., whose names end in ${EXEEXT}. 138# All files that are created by the linker, i.e., whose names end in ${EXEEXT}.
137EXE_FILES = ${INSTALLABLES} ${UTILITIES} ${DONT_INSTALL} 139EXE_FILES = ${INSTALLABLES} ${UTILITIES} ${DONT_INSTALL}
diff --git a/lib-src/makefile.w32-in b/lib-src/makefile.w32-in
index 9656a3badec..dee80c4b560 100644
--- a/lib-src/makefile.w32-in
+++ b/lib-src/makefile.w32-in
@@ -251,6 +251,7 @@ lisp2 = \
251 $(lispsource)register.elc \ 251 $(lispsource)register.elc \
252 $(lispsource)replace.elc \ 252 $(lispsource)replace.elc \
253 $(lispsource)simple.elc \ 253 $(lispsource)simple.elc \
254 $(lispsource)emacs-lisp/nadvice.elc \
254 $(lispsource)minibuffer.elc \ 255 $(lispsource)minibuffer.elc \
255 $(lispsource)startup.elc \ 256 $(lispsource)startup.elc \
256 $(lispsource)subr.elc \ 257 $(lispsource)subr.elc \
diff --git a/lib-src/movemail.c b/lib-src/movemail.c
index 81ac8aa187c..9434782cb17 100644
--- a/lib-src/movemail.c
+++ b/lib-src/movemail.c
@@ -304,24 +304,13 @@ main (int argc, char **argv)
304 304
305 memcpy (tempname, inname, inname_dirlen); 305 memcpy (tempname, inname, inname_dirlen);
306 strcpy (tempname + inname_dirlen, "EXXXXXX"); 306 strcpy (tempname + inname_dirlen, "EXXXXXX");
307#ifdef HAVE_MKSTEMP 307 desc = mkostemp (tempname, 0);
308 desc = mkstemp (tempname);
309#else
310 mktemp (tempname);
311 if (!*tempname)
312 desc = -1;
313 else
314 {
315 unlink (tempname);
316 desc = open (tempname, O_WRONLY | O_CREAT | O_EXCL, 0600);
317 }
318#endif
319 if (desc < 0) 308 if (desc < 0)
320 { 309 {
321 int mkstemp_errno = errno; 310 int mkostemp_errno = errno;
322 error ("error while creating what would become the lock file", 311 error ("error while creating what would become the lock file",
323 0, 0); 312 0, 0);
324 errno = mkstemp_errno; 313 errno = mkostemp_errno;
325 pfatal_with_name (tempname); 314 pfatal_with_name (tempname);
326 } 315 }
327 close (desc); 316 close (desc);
diff --git a/lib-src/ntlib.c b/lib-src/ntlib.c
index 41b4e3a0cbc..ab7d8b590df 100644
--- a/lib-src/ntlib.c
+++ b/lib-src/ntlib.c
@@ -422,3 +422,72 @@ lstat (const char * path, struct stat * buf)
422{ 422{
423 return stat (path, buf); 423 return stat (path, buf);
424} 424}
425
426/* Implementation of mkostemp for MS-Windows, to avoid race conditions
427 when using mktemp. Copied from w32.c.
428
429 This is used only in update-game-score.c. It is overkill for that
430 use case, since update-game-score renames the temporary file into
431 the game score file, which isn't atomic on MS-Windows anyway, when
432 the game score already existed before running the program, which it
433 almost always does. But using a simpler implementation just to
434 make a point is uneconomical... */
435
436int
437mkostemp (char * template, int flags)
438{
439 char * p;
440 int i, fd = -1;
441 unsigned uid = GetCurrentThreadId ();
442 int save_errno = errno;
443 static char first_char[] = "abcdefghijklmnopqrstuvwyz0123456789!%-_@#";
444
445 errno = EINVAL;
446 if (template == NULL)
447 return -1;
448
449 p = template + strlen (template);
450 i = 5;
451 /* replace up to the last 5 X's with uid in decimal */
452 while (--p >= template && p[0] == 'X' && --i >= 0)
453 {
454 p[0] = '0' + uid % 10;
455 uid /= 10;
456 }
457
458 if (i < 0 && p[0] == 'X')
459 {
460 i = 0;
461 do
462 {
463 p[0] = first_char[i];
464 if ((fd = open (template,
465 flags | _O_CREAT | _O_EXCL | _O_RDWR,
466 S_IRUSR | S_IWUSR)) >= 0
467 || errno != EEXIST)
468 {
469 if (fd >= 0)
470 errno = save_errno;
471 return fd;
472 }
473 }
474 while (++i < sizeof (first_char));
475 }
476
477 /* Template is badly formed or else we can't generate a unique name. */
478 return -1;
479}
480
481/* On Windows, you cannot rename into an existing file. */
482int
483sys_rename (const char *from, const char *to)
484{
485 int retval = rename (from, to);
486
487 if (retval < 0 && errno == EEXIST)
488 {
489 if (unlink (to) == 0)
490 retval = rename (from, to);
491 }
492 return retval;
493}
diff --git a/lib-src/ntlib.h b/lib-src/ntlib.h
index 3e48d2997e0..ab5f5ea3b89 100644
--- a/lib-src/ntlib.h
+++ b/lib-src/ntlib.h
@@ -22,6 +22,7 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
22/* Include these headers now so we don't have to worry about include 22/* Include these headers now so we don't have to worry about include
23 order dependencies in common source files. */ 23 order dependencies in common source files. */
24#include <direct.h> 24#include <direct.h>
25#include <fcntl.h>
25#include <io.h> 26#include <io.h>
26#include <stdio.h> 27#include <stdio.h>
27 28
@@ -41,6 +42,7 @@ int setuid (unsigned uid);
41int setregid (unsigned rgid, unsigned gid); 42int setregid (unsigned rgid, unsigned gid);
42char * getpass (const char * prompt); 43char * getpass (const char * prompt);
43int fchown (int fd, unsigned uid, unsigned gid); 44int fchown (int fd, unsigned uid, unsigned gid);
45int mkostemp (char * template, int flags);
44 46
45/* redirect or undo interceptions created by config.h */ 47/* redirect or undo interceptions created by config.h */
46#undef access 48#undef access
@@ -61,15 +63,12 @@ int fchown (int fd, unsigned uid, unsigned gid);
61#undef fopen 63#undef fopen
62#undef mkdir 64#undef mkdir
63#define mkdir _mkdir 65#define mkdir _mkdir
64#undef mktemp
65#define mktemp _mktemp
66#undef open 66#undef open
67#define open _open 67#define open _open
68#undef pipe 68#undef pipe
69#define pipe _pipe 69#define pipe _pipe
70#undef read 70#undef read
71#define read _read 71#define read _read
72#undef rename
73#undef rmdir 72#undef rmdir
74#define rmdir _rmdir 73#define rmdir _rmdir
75#undef unlink 74#undef unlink
diff --git a/lib-src/update-game-score.c b/lib-src/update-game-score.c
index ec8b4317770..92c1663f658 100644
--- a/lib-src/update-game-score.c
+++ b/lib-src/update-game-score.c
@@ -228,10 +228,11 @@ static int
228read_score (FILE *f, struct score_entry *score) 228read_score (FILE *f, struct score_entry *score)
229{ 229{
230 int c; 230 int c;
231 if ((c = getc (f)) != EOF)
232 ungetc (c, f);
231 if (feof (f)) 233 if (feof (f))
232 return 1; 234 return 1;
233 while ((c = getc (f)) != EOF 235 for (score->score = 0; (c = getc (f)) != EOF && isdigit (c); )
234 && isdigit (c))
235 { 236 {
236 score->score *= 10; 237 score->score *= 10;
237 score->score += (c-48); 238 score->score += (c-48);
@@ -311,34 +312,38 @@ read_score (FILE *f, struct score_entry *score)
311static int 312static int
312read_scores (const char *filename, struct score_entry **scores, int *count) 313read_scores (const char *filename, struct score_entry **scores, int *count)
313{ 314{
314 int readval, scorecount, cursize; 315 int readval = -1, scorecount, cursize;
315 struct score_entry *ret; 316 struct score_entry *ret;
316 FILE *f = fopen (filename, "r"); 317 FILE *f = fopen (filename, "r");
318 int retval = -1;
317 if (!f) 319 if (!f)
318 return -1; 320 return -1;
319 scorecount = 0; 321 scorecount = 0;
320 cursize = 16; 322 cursize = 16;
321 ret = (struct score_entry *) malloc (sizeof (struct score_entry) * cursize); 323 ret = (struct score_entry *) malloc (sizeof (struct score_entry) * cursize);
322 if (!ret) 324 if (ret)
323 return -1;
324 while ((readval = read_score (f, &ret[scorecount])) == 0)
325 { 325 {
326 /* We encountered an error. */ 326 while ((readval = read_score (f, &ret[scorecount])) == 0)
327 if (readval < 0)
328 return -1;
329 scorecount++;
330 if (scorecount >= cursize)
331 { 327 {
332 cursize *= 2; 328 scorecount++;
333 ret = (struct score_entry *) 329 if (scorecount >= cursize)
334 realloc (ret, (sizeof (struct score_entry) * cursize)); 330 {
335 if (!ret) 331 cursize *= 2;
336 return -1; 332 ret = (struct score_entry *)
333 realloc (ret, (sizeof (struct score_entry) * cursize));
334 if (!ret)
335 break;
336 }
337 } 337 }
338 } 338 }
339 *count = scorecount; 339 if (readval > 0)
340 *scores = ret; 340 {
341 return 0; 341 *count = scorecount;
342 *scores = ret;
343 retval = 0;
344 }
345 fclose (f);
346 return retval;
342} 347}
343 348
344static int 349static int
@@ -383,6 +388,7 @@ sort_scores (struct score_entry *scores, int count, int reverse)
383static int 388static int
384write_scores (const char *filename, const struct score_entry *scores, int count) 389write_scores (const char *filename, const struct score_entry *scores, int count)
385{ 390{
391 int fd;
386 FILE *f; 392 FILE *f;
387 int i; 393 int i;
388 char *tempfile = malloc (strlen (filename) + strlen (".tempXXXXXX") + 1); 394 char *tempfile = malloc (strlen (filename) + strlen (".tempXXXXXX") + 1);
@@ -390,12 +396,11 @@ write_scores (const char *filename, const struct score_entry *scores, int count)
390 return -1; 396 return -1;
391 strcpy (tempfile, filename); 397 strcpy (tempfile, filename);
392 strcat (tempfile, ".tempXXXXXX"); 398 strcat (tempfile, ".tempXXXXXX");
393#ifdef HAVE_MKSTEMP 399 fd = mkostemp (tempfile, 0);
394 if (mkstemp (tempfile) < 0 400 if (fd < 0)
395#else 401 return -1;
396 if (mktemp (tempfile) != tempfile 402 f = fdopen (fd, "w");
397#endif 403 if (! f)
398 || !(f = fopen (tempfile, "w")))
399 return -1; 404 return -1;
400 for (i = 0; i < count; i++) 405 for (i = 0; i < count; i++)
401 if (fprintf (f, "%ld %s %s\n", scores[i].score, scores[i].username, 406 if (fprintf (f, "%ld %s %s\n", scores[i].score, scores[i].username,
@@ -461,5 +466,4 @@ unlock_file (const char *filename, void *state)
461 return ret; 466 return ret;
462} 467}
463 468
464
465/* update-game-score.c ends here */ 469/* update-game-score.c ends here */
diff --git a/lib-src/update-game-score.exe.manifest b/lib-src/update-game-score.exe.manifest
new file mode 100644
index 00000000000..1db836bec6b
--- /dev/null
+++ b/lib-src/update-game-score.exe.manifest
@@ -0,0 +1,10 @@
1<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
2<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
3 <v3:trustInfo xmlns:v3="urn:schemas-microsoft-com:asm.v3">
4 <v3:security>
5 <v3:requestedPrivileges>
6 <v3:requestedExecutionLevel level="asInvoker" />
7 </v3:requestedPrivileges>
8 </v3:security>
9 </v3:trustInfo>
10</assembly>