summaryrefslogtreecommitdiff
path: root/lib-src
diff options
context:
space:
mode:
authorEli Zaretskii <eliz@gnu.org>2017-08-12 11:29:37 +0300
committerEli Zaretskii <eliz@gnu.org>2017-08-12 11:29:37 +0300
commit8cc8ad02bd5c410c61680735149ce7caf67f088d (patch)
treef99ec13f9647acb1bdc89a2691943fa1802b9d33 /lib-src
parent84288cf4211a4490c0155d3c0022617b92294f49 (diff)
downloademacs-8cc8ad02bd5c410c61680735149ce7caf67f088d.tar.gz
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/>. */
char *sys_ctime (const time_t *);
FILE *sys_fopen (const char *, const char *);
+int sys_mkdir (const char *, mode_t);
int sys_chdir (const char *);
int mkostemp (char *, int);
int sys_rename (const char *, const char *);
+int sys_open (const char *, int, int);
/* MinGW64 defines _TIMEZONE_DEFINED and defines 'struct timespec' in
its system headers. */
@@ -245,6 +247,12 @@ sys_chdir (const char * path)
return _chdir (path);
}
+int
+sys_mkdir (const char * path, mode_t mode)
+{
+ return _mkdir (path);
+}
+
static FILETIME utc_base_ft;
static long double utc_base;
static int init = 0;
@@ -396,61 +404,6 @@ lstat (const char * path, struct stat * buf)
return stat (path, buf);
}
-/* Implementation of mkostemp for MS-Windows, to avoid race conditions
- when using mktemp. Copied from w32.c.
-
- This is used only in update-game-score.c. It is overkill for that
- use case, since update-game-score renames the temporary file into
- the game score file, which isn't atomic on MS-Windows anyway, when
- the game score already existed before running the program, which it
- almost always does. But using a simpler implementation just to
- make a point is uneconomical... */
-
-int
-mkostemp (char * template, int flags)
-{
- char * p;
- int i, fd = -1;
- unsigned uid = GetCurrentThreadId ();
- int save_errno = errno;
- static char first_char[] = "abcdefghijklmnopqrstuvwyz0123456789!%-_@#";
-
- errno = EINVAL;
- if (template == NULL)
- return -1;
-
- p = template + strlen (template);
- i = 5;
- /* replace up to the last 5 X's with uid in decimal */
- while (--p >= template && p[0] == 'X' && --i >= 0)
- {
- p[0] = '0' + uid % 10;
- uid /= 10;
- }
-
- if (i < 0 && p[0] == 'X')
- {
- i = 0;
- do
- {
- p[0] = first_char[i];
- if ((fd = open (template,
- flags | _O_CREAT | _O_EXCL | _O_RDWR,
- S_IRUSR | S_IWUSR)) >= 0
- || errno != EEXIST)
- {
- if (fd >= 0)
- errno = save_errno;
- return fd;
- }
- }
- while (++i < sizeof (first_char));
- }
-
- /* Template is badly formed or else we can't generate a unique name. */
- return -1;
-}
-
/* On Windows, you cannot rename into an existing file. */
int
sys_rename (const char *from, const char *to)
@@ -464,3 +417,9 @@ sys_rename (const char *from, const char *to)
}
return retval;
}
+
+int
+sys_open (const char * path, int oflag, int mode)
+{
+ return _open (path, oflag, mode);
+}
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);
#undef dup2
#define dup2 _dup2
#undef fopen
-#undef mkdir
-#define mkdir _mkdir
-#undef open
-#define open _open
#undef pipe
#define pipe _pipe
#undef read