]> git.eshelyaron.com Git - emacs.git/commitdiff
(sys_open): Try to open file without _O_CREAT first, to be
authorGerd Moellmann <gerd@gnu.org>
Tue, 10 Apr 2001 12:15:25 +0000 (12:15 +0000)
committerGerd Moellmann <gerd@gnu.org>
Tue, 10 Apr 2001 12:15:25 +0000 (12:15 +0000)
able to write to hidden and system files.  Make file handles
non-inheritable.

src/w32.c

index 1fdb47383cba25b2a06e0442544a0778eef604a9..f5ea84a6111a0339fc487f2a4d9b17416610b495 100644 (file)
--- a/src/w32.c
+++ b/src/w32.c
@@ -1,5 +1,5 @@
 /* Utility and Unix shadow routines for GNU Emacs on the Microsoft W32 API.
-   Copyright (C) 1994, 1995 Free Software Foundation, Inc.
+   Copyright (C) 1994, 1995, 2000, 2001 Free Software Foundation, Inc.
 
 This file is part of GNU Emacs.
 
@@ -1819,8 +1819,14 @@ sys_mktemp (char * template)
 int
 sys_open (const char * path, int oflag, int mode)
 {
-  /* Force all file handles to be non-inheritable. */
-  return _open (map_w32_filename (path, NULL), oflag | _O_NOINHERIT, 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);
+  if (res >= 0)
+    return res;
+  return _open (mpath, oflag | _O_NOINHERIT, mode);
 }
 
 int