[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] trunk r113687: Implement mkostemp for MS-Windows.
From: |
Eli Zaretskii |
Subject: |
[Emacs-diffs] trunk r113687: Implement mkostemp for MS-Windows. |
Date: |
Sun, 04 Aug 2013 15:33:23 +0000 |
User-agent: |
Bazaar (2.6b2) |
------------------------------------------------------------
revno: 113687
revision-id: address@hidden
parent: address@hidden
fixes bug: http://debbugs.gnu.org/15015
committer: Eli Zaretskii <address@hidden>
branch nick: trunk
timestamp: Sun 2013-08-04 18:32:12 +0300
message:
Implement mkostemp for MS-Windows.
nt/mingw-cfg.site (ac_cv_func_mkostemp): New var with value of "yes".
nt/inc/ms-w32.h (mkostemp): Declare prototype.
nt/config.nt (HAVE_MKOSTEMP): Define to 1.
src/w32.c (mkostemp): New function.
(mktemp): Remove, no longer used. Most of the code reused in mkostemp.
modified:
nt/ChangeLog changelog-20091113204419-o5vbwnq5f7feedwu-1545
nt/config.nt config.nt-20091113204419-o5vbwnq5f7feedwu-878
nt/inc/ms-w32.h msw32.h-20091113204419-o5vbwnq5f7feedwu-807
nt/mingw-cfg.site mingwcfg.site-20130329112849-w6zo8bvz3ddvox05-1
src/ChangeLog changelog-20091113204419-o5vbwnq5f7feedwu-1438
src/w32.c w32.c-20091113204419-o5vbwnq5f7feedwu-808
=== modified file 'nt/ChangeLog'
--- a/nt/ChangeLog 2013-07-07 18:48:16 +0000
+++ b/nt/ChangeLog 2013-08-04 15:32:12 +0000
@@ -1,3 +1,12 @@
+2013-08-04 Eli Zaretskii <address@hidden>
+
+ * mingw-cfg.site (ac_cv_func_mkostemp): New var with value of
+ "yes".
+
+ * inc/ms-w32.h (mkostemp): Declare prototype.
+
+ * config.nt (HAVE_MKOSTEMP): Define to 1. (Bug#15015)
+
2013-07-07 Eli Zaretskii <address@hidden>
* inc/sys/socket.h (F_SETFD, O_CLOEXEC, F_DUPFD_CLOEXEC)
=== modified file 'nt/config.nt'
--- a/nt/config.nt 2013-06-03 19:06:09 +0000
+++ b/nt/config.nt 2013-08-04 15:32:12 +0000
@@ -796,6 +796,9 @@
systems that support xmenu.c. */
#undef HAVE_MENUS
+/* Define to 1 if you have the `mkostemp' function. */
+#define HAVE_MKOSTEMP 1
+
/* Define to 1 if you have the `mkstemp' function. */
#undef HAVE_MKSTEMP
=== modified file 'nt/inc/ms-w32.h'
--- a/nt/inc/ms-w32.h 2013-07-07 18:00:14 +0000
+++ b/nt/inc/ms-w32.h 2013-08-04 15:32:12 +0000
@@ -450,6 +450,8 @@
extern void * memrchr (void const *, int, size_t);
+extern int mkostemp (char *, int);
+
#if defined (__MINGW32__)
=== modified file 'nt/mingw-cfg.site'
--- a/nt/mingw-cfg.site 2013-07-07 18:00:14 +0000
+++ b/nt/mingw-cfg.site 2013-08-04 15:32:12 +0000
@@ -60,6 +60,7 @@
# Implemented as sys_socket in w32.c
ac_cv_func_socket=yes
# Implemented in w32.c
+ac_cv_func_mkostemp=yes
ac_cv_func_readlink=yes
ac_cv_func_symlink=yes
# Avoid run-time tests of readlink and symlink, which will fail
=== modified file 'src/ChangeLog'
--- a/src/ChangeLog 2013-08-04 04:07:18 +0000
+++ b/src/ChangeLog 2013-08-04 15:32:12 +0000
@@ -1,3 +1,9 @@
+2013-08-04 Eli Zaretskii <address@hidden>
+
+ * w32.c (mkostemp): New function.
+ (mktemp): Remove, no longer used. Most of the code reused in
+ mkostemp. (Bug#15015)
+
2013-08-04 Dmitry Antipov <address@hidden>
* dispnew.c (glyph_matrix_count, glyph_pool_count):
=== modified file 'src/w32.c'
--- a/src/w32.c 2013-07-16 18:30:52 +0000
+++ b/src/w32.c 2013-08-04 15:32:12 +0000
@@ -3414,25 +3414,46 @@
return _mkdir (map_w32_filename (path, NULL));
}
-/* Because of long name mapping issues, we need to implement this
- ourselves. Also, MSVC's _mktemp returns NULL when it can't generate
- a unique name, instead of setting the input template to an empty
- string.
-
- Standard algorithm seems to be use pid or tid with a letter on the
- front (in place of the 6 X's) and cycle through the letters to find a
- unique name. We extend that to allow any reasonable character as the
- first of the 6 X's. */
-char *
-sys_mktemp (char * template)
+int
+sys_open (const char * path, int oflag, int mode)
+{
+ const char* mpath = map_w32_filename (path, NULL);
+ int res = -1;
+
+ /* If possible, try to open file without _O_CREAT, to be able to
+ write to existing hidden and system files. Force all file
+ handles to be non-inheritable. */
+ if ((oflag & (_O_CREAT | _O_EXCL)) != (_O_CREAT | _O_EXCL))
+ res = _open (mpath, (oflag & ~_O_CREAT) | _O_NOINHERIT, mode);
+ if (res < 0)
+ res = _open (mpath, oflag | _O_NOINHERIT, mode);
+
+ return res;
+}
+
+/* Implementation of mkostemp for MS-Windows, to avoid race conditions
+ when using mktemp.
+
+ Standard algorithm for generating a temporary file name seems to be
+ use pid or tid with a letter on the front (in place of the 6 X's)
+ and cycle through the letters to find a unique name. We extend
+ that to allow any reasonable character as the first of the 6 X's,
+ so that the number of simultaneously used temporary files will be
+ greater. */
+
+int
+mkostemp (char * template, int flags)
{
char * p;
- int i;
+ int i, fd = -1;
unsigned uid = GetCurrentThreadId ();
+ int save_errno = errno;
static char first_char[] = "address@hidden";
+ errno = EINVAL;
if (template == NULL)
- return NULL;
+ return -1;
+
p = template + strlen (template);
i = 5;
/* replace up to the last 5 X's with uid in decimal */
@@ -3447,38 +3468,22 @@
i = 0;
do
{
- int save_errno = errno;
p[0] = first_char[i];
- if (faccessat (AT_FDCWD, template, F_OK, AT_EACCESS) < 0)
+ if ((fd = sys_open (template,
+ flags | _O_CREAT | _O_EXCL | _O_RDWR,
+ S_IRUSR | S_IWUSR)) >= 0
+ || errno != EEXIST)
{
- errno = save_errno;
- return template;
+ 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,
- so return empty string */
- template[0] = 0;
- return template;
-}
-
-int
-sys_open (const char * path, int oflag, int mode)
-{
- const char* mpath = map_w32_filename (path, NULL);
- int res = -1;
-
- /* If possible, try to open file without _O_CREAT, to be able to
- write to existing hidden and system files. Force all file
- handles to be non-inheritable. */
- if ((oflag & (_O_CREAT | _O_EXCL)) != (_O_CREAT | _O_EXCL))
- res = _open (mpath, (oflag & ~_O_CREAT) | _O_NOINHERIT, mode);
- if (res < 0)
- res = _open (mpath, oflag | _O_NOINHERIT, mode);
-
- return res;
+ /* Template is badly formed or else we can't generate a unique name. */
+ return -1;
}
int
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Emacs-diffs] trunk r113687: Implement mkostemp for MS-Windows.,
Eli Zaretskii <=