[PATCH] Updated use of pmode flag in _s_open - set permissions of the file after it's been created.

Ivan Peevski ipeevski at gmail.com
Fri Oct 17 00:43:15 CDT 2008


Followed the documentation at http://msdn.microsoft.com/en-us/library/w7sa2b22(VS.80).aspx. First, ignore pmode if the file already exist. Then, apply pmode permissions to the file, once it has been created.
---
 dlls/msvcrt/file.c |   14 +++++++++-----
 1 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/dlls/msvcrt/file.c b/dlls/msvcrt/file.c
index c78e46c..d998c05 100644
--- a/dlls/msvcrt/file.c
+++ b/dlls/msvcrt/file.c
@@ -1419,8 +1419,9 @@ int CDECL MSVCRT__pipe(int *pfds, unsigned int psize, int textmode)
 int CDECL MSVCRT__sopen( const char *path, int oflags, int shflags, ... )
 {
   va_list ap;
-  int pmode;
+  int pmode = 0;
   DWORD access = 0, creation = 0, attrib;
+  struct stat buf;
   DWORD sharing;
   int wxflag = 0, fd;
   HANDLE hand;
@@ -1444,10 +1445,9 @@ int CDECL MSVCRT__sopen( const char *path, int oflags, int shflags, ... )
       pmode = va_arg(ap, int);
     va_end(ap);
 
-    if(pmode & ~(MSVCRT__S_IREAD | MSVCRT__S_IWRITE))
-      FIXME(": pmode 0x%04x ignored\n", pmode);
-    else
-      WARN(": pmode 0x%04x ignored\n", pmode);
+    /* Ignore _S_IREAD and _S_IWRITE if file exists. */
+    if (stat(path, &buf) != 0)
+      pmode = pmode & (MSVCRT__S_IREAD | MSVCRT__S_IWRITE); /*relevant flags*/
 
     if (oflags & MSVCRT__O_EXCL)
       creation = CREATE_NEW;
@@ -1503,6 +1503,10 @@ int CDECL MSVCRT__sopen( const char *path, int oflags, int shflags, ... )
     return -1;
   }
 
+  /* Apply file permissions as needed. */
+  if (pmode)
+    MSVCRT__chmod(path, pmode);
+
   fd = msvcrt_alloc_fd(hand, wxflag);
 
   TRACE(":fd (%d) handle (%p)\n",fd, hand);
-- 
1.5.4.3




More information about the wine-patches mailing list