aboutsummaryrefslogtreecommitdiffstats
path: root/lib-src
diff options
context:
space:
mode:
authorEli Zaretskii2017-08-12 11:29:37 +0300
committerEli Zaretskii2017-08-12 11:29:37 +0300
commit8cc8ad02bd5c410c61680735149ce7caf67f088d (patch)
treef99ec13f9647acb1bdc89a2691943fa1802b9d33 /lib-src
parent84288cf4211a4490c0155d3c0022617b92294f49 (diff)
downloademacs-8cc8ad02bd5c410c61680735149ce7caf67f088d.tar.gz
emacs-8cc8ad02bd5c410c61680735149ce7caf67f088d.zip
Use Gnulib 'tempname' on MS-Windows
* lib-src/ntlib.h (mkdir, open): Remove redefinitions. They are now in nt/inc/ms-w32.h. * lib-src/ntlib.c (sys_mkdir, sys_open): New functions. (mkostemp): Remove. * src/w32.c (mkostemp): Remove. (sys_mkdir): Accept a second (unused) argument. * src/fileio.c (Fmake_directory_internal): Remove the WINDOWSNT specific call to mkdir. (Bug#28023) * nt/inc/ms-w32.h (mkdir): Remove from "#ifdef emacs" and redefine to accept 2 arguments. (open): Remove from "#ifdef emacs". * nt/mingw-cfg.site (ac_cv_func_mkostemp): Remove. * nt/gnulib-cfg.mk (OMIT_GNULIB_MODULE_mkostemp) (OMIT_GNULIB_MODULE_tempname): Remove.
Diffstat (limited to 'lib-src')
-rw-r--r--lib-src/ntlib.c69
-rw-r--r--lib-src/ntlib.h4
2 files changed, 14 insertions, 59 deletions
diff --git a/lib-src/ntlib.c b/lib-src/ntlib.c
index 78ba9061f6b..9908f0fa452 100644
--- a/lib-src/ntlib.c
+++ b/lib-src/ntlib.c
@@ -36,9 +36,11 @@ along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
36 36
37char *sys_ctime (const time_t *); 37char *sys_ctime (const time_t *);
38FILE *sys_fopen (const char *, const char *); 38FILE *sys_fopen (const char *, const char *);
39int sys_mkdir (const char *, mode_t);
39int sys_chdir (const char *); 40int sys_chdir (const char *);
40int mkostemp (char *, int); 41int mkostemp (char *, int);
41int sys_rename (const char *, const char *); 42int sys_rename (const char *, const char *);
43int sys_open (const char *, int, int);
42 44
43/* MinGW64 defines _TIMEZONE_DEFINED and defines 'struct timespec' in 45/* MinGW64 defines _TIMEZONE_DEFINED and defines 'struct timespec' in
44 its system headers. */ 46 its system headers. */
@@ -245,6 +247,12 @@ sys_chdir (const char * path)
245 return _chdir (path); 247 return _chdir (path);
246} 248}
247 249
250int
251sys_mkdir (const char * path, mode_t mode)
252{
253 return _mkdir (path);
254}
255
248static FILETIME utc_base_ft; 256static FILETIME utc_base_ft;
249static long double utc_base; 257static long double utc_base;
250static int init = 0; 258static int init = 0;
@@ -396,61 +404,6 @@ lstat (const char * path, struct stat * buf)
396 return stat (path, buf); 404 return stat (path, buf);
397} 405}
398 406
399/* Implementation of mkostemp for MS-Windows, to avoid race conditions
400 when using mktemp. Copied from w32.c.
401
402 This is used only in update-game-score.c. It is overkill for that
403 use case, since update-game-score renames the temporary file into
404 the game score file, which isn't atomic on MS-Windows anyway, when
405 the game score already existed before running the program, which it
406 almost always does. But using a simpler implementation just to
407 make a point is uneconomical... */
408
409int
410mkostemp (char * template, int flags)
411{
412 char * p;
413 int i, fd = -1;
414 unsigned uid = GetCurrentThreadId ();
415 int save_errno = errno;
416 static char first_char[] = "abcdefghijklmnopqrstuvwyz0123456789!%-_@#";
417
418 errno = EINVAL;
419 if (template == NULL)
420 return -1;
421
422 p = template + strlen (template);
423 i = 5;
424 /* replace up to the last 5 X's with uid in decimal */
425 while (--p >= template && p[0] == 'X' && --i >= 0)
426 {
427 p[0] = '0' + uid % 10;
428 uid /= 10;
429 }
430
431 if (i < 0 && p[0] == 'X')
432 {
433 i = 0;
434 do
435 {
436 p[0] = first_char[i];
437 if ((fd = open (template,
438 flags | _O_CREAT | _O_EXCL | _O_RDWR,
439 S_IRUSR | S_IWUSR)) >= 0
440 || errno != EEXIST)
441 {
442 if (fd >= 0)
443 errno = save_errno;
444 return fd;
445 }
446 }
447 while (++i < sizeof (first_char));
448 }
449
450 /* Template is badly formed or else we can't generate a unique name. */
451 return -1;
452}
453
454/* On Windows, you cannot rename into an existing file. */ 407/* On Windows, you cannot rename into an existing file. */
455int 408int
456sys_rename (const char *from, const char *to) 409sys_rename (const char *from, const char *to)
@@ -464,3 +417,9 @@ sys_rename (const char *from, const char *to)
464 } 417 }
465 return retval; 418 return retval;
466} 419}
420
421int
422sys_open (const char * path, int oflag, int mode)
423{
424 return _open (path, oflag, mode);
425}
diff --git a/lib-src/ntlib.h b/lib-src/ntlib.h
index 32189dcc7a0..b69a40b4f03 100644
--- a/lib-src/ntlib.h
+++ b/lib-src/ntlib.h
@@ -58,10 +58,6 @@ int fchown (int fd, unsigned uid, unsigned gid);
58#undef dup2 58#undef dup2
59#define dup2 _dup2 59#define dup2 _dup2
60#undef fopen 60#undef fopen
61#undef mkdir
62#define mkdir _mkdir
63#undef open
64#define open _open
65#undef pipe 61#undef pipe
66#define pipe _pipe 62#define pipe _pipe
67#undef read 63#undef read