]> code.delx.au - gnu-emacs/blobdiff - src/w32.c
Implement CLASH_DETECTION for MS-Windows.
[gnu-emacs] / src / w32.c
index 5011642adf27c9c87f678f0a39260ea89af43707..aff9771e4bbbaa15e7ca453551029204e395131e 100644 (file)
--- a/src/w32.c
+++ b/src/w32.c
@@ -3402,10 +3402,13 @@ int
 sys_open (const char * path, int oflag, int mode)
 {
   const char* mpath = map_w32_filename (path, NULL);
-  /* Try to open file without _O_CREAT, to be able to write to hidden
-     and system files. Force all file handles to be
-     non-inheritable. */
-  int res = _open (mpath, (oflag & ~_O_CREAT) | _O_NOINHERIT, mode);
+  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);
   if (res >= 0 && res < MAXDESC)