diff options
| author | Eli Zaretskii | 2017-08-12 11:29:37 +0300 |
|---|---|---|
| committer | Eli Zaretskii | 2017-08-12 11:29:37 +0300 |
| commit | 8cc8ad02bd5c410c61680735149ce7caf67f088d (patch) | |
| tree | f99ec13f9647acb1bdc89a2691943fa1802b9d33 /src | |
| parent | 84288cf4211a4490c0155d3c0022617b92294f49 (diff) | |
| download | emacs-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 'src')
| -rw-r--r-- | src/fileio.c | 4 | ||||
| -rw-r--r-- | src/w32.c | 58 |
2 files changed, 1 insertions, 61 deletions
diff --git a/src/fileio.c b/src/fileio.c index 9aae7d997ee..8506a198fe3 100644 --- a/src/fileio.c +++ b/src/fileio.c | |||
| @@ -2178,11 +2178,7 @@ DEFUN ("make-directory-internal", Fmake_directory_internal, | |||
| 2178 | 2178 | ||
| 2179 | dir = SSDATA (encoded_dir); | 2179 | dir = SSDATA (encoded_dir); |
| 2180 | 2180 | ||
| 2181 | #ifdef WINDOWSNT | ||
| 2182 | if (mkdir (dir) != 0) | ||
| 2183 | #else | ||
| 2184 | if (mkdir (dir, 0777 & ~auto_saving_dir_umask) != 0) | 2181 | if (mkdir (dir, 0777 & ~auto_saving_dir_umask) != 0) |
| 2185 | #endif | ||
| 2186 | report_file_error ("Creating directory", directory); | 2182 | report_file_error ("Creating directory", directory); |
| 2187 | 2183 | ||
| 2188 | return Qnil; | 2184 | return Qnil; |
| @@ -74,7 +74,6 @@ char *sys_ctime (const time_t *); | |||
| 74 | int sys_chdir (const char *); | 74 | int sys_chdir (const char *); |
| 75 | int sys_creat (const char *, int); | 75 | int sys_creat (const char *, int); |
| 76 | FILE *sys_fopen (const char *, const char *); | 76 | FILE *sys_fopen (const char *, const char *); |
| 77 | int sys_mkdir (const char *); | ||
| 78 | int sys_open (const char *, int, int); | 77 | int sys_open (const char *, int, int); |
| 79 | int sys_rename (char const *, char const *); | 78 | int sys_rename (char const *, char const *); |
| 80 | int sys_rmdir (const char *); | 79 | int sys_rmdir (const char *); |
| @@ -4344,7 +4343,7 @@ sys_link (const char * old, const char * new) | |||
| 4344 | } | 4343 | } |
| 4345 | 4344 | ||
| 4346 | int | 4345 | int |
| 4347 | sys_mkdir (const char * path) | 4346 | sys_mkdir (const char * path, mode_t mode) |
| 4348 | { | 4347 | { |
| 4349 | path = map_w32_filename (path, NULL); | 4348 | path = map_w32_filename (path, NULL); |
| 4350 | 4349 | ||
| @@ -4397,61 +4396,6 @@ sys_open (const char * path, int oflag, int mode) | |||
| 4397 | return res; | 4396 | return res; |
| 4398 | } | 4397 | } |
| 4399 | 4398 | ||
| 4400 | /* Implementation of mkostemp for MS-Windows, to avoid race conditions | ||
| 4401 | when using mktemp. | ||
| 4402 | |||
| 4403 | Standard algorithm for generating a temporary file name seems to be | ||
| 4404 | use pid or tid with a letter on the front (in place of the 6 X's) | ||
| 4405 | and cycle through the letters to find a unique name. We extend | ||
| 4406 | that to allow any reasonable character as the first of the 6 X's, | ||
| 4407 | so that the number of simultaneously used temporary files will be | ||
| 4408 | greater. */ | ||
| 4409 | |||
| 4410 | int | ||
| 4411 | mkostemp (char * template, int flags) | ||
| 4412 | { | ||
| 4413 | char * p; | ||
| 4414 | int i, fd = -1; | ||
| 4415 | unsigned uid = GetCurrentThreadId (); | ||
| 4416 | int save_errno = errno; | ||
| 4417 | static char first_char[] = "abcdefghijklmnopqrstuvwyz0123456789!%-_@#"; | ||
| 4418 | |||
| 4419 | errno = EINVAL; | ||
| 4420 | if (template == NULL) | ||
| 4421 | return -1; | ||
| 4422 | |||
| 4423 | p = template + strlen (template); | ||
| 4424 | i = 5; | ||
| 4425 | /* replace up to the last 5 X's with uid in decimal */ | ||
| 4426 | while (--p >= template && p[0] == 'X' && --i >= 0) | ||
| 4427 | { | ||
| 4428 | p[0] = '0' + uid % 10; | ||
| 4429 | uid /= 10; | ||
| 4430 | } | ||
| 4431 | |||
| 4432 | if (i < 0 && p[0] == 'X') | ||
| 4433 | { | ||
| 4434 | i = 0; | ||
| 4435 | do | ||
| 4436 | { | ||
| 4437 | p[0] = first_char[i]; | ||
| 4438 | if ((fd = sys_open (template, | ||
| 4439 | flags | _O_CREAT | _O_EXCL | _O_RDWR, | ||
| 4440 | S_IRUSR | S_IWUSR)) >= 0 | ||
| 4441 | || errno != EEXIST) | ||
| 4442 | { | ||
| 4443 | if (fd >= 0) | ||
| 4444 | errno = save_errno; | ||
| 4445 | return fd; | ||
| 4446 | } | ||
| 4447 | } | ||
| 4448 | while (++i < sizeof (first_char)); | ||
| 4449 | } | ||
| 4450 | |||
| 4451 | /* Template is badly formed or else we can't generate a unique name. */ | ||
| 4452 | return -1; | ||
| 4453 | } | ||
| 4454 | |||
| 4455 | int | 4399 | int |
| 4456 | fchmod (int fd, mode_t mode) | 4400 | fchmod (int fd, mode_t mode) |
| 4457 | { | 4401 | { |