[vlc-commits] Win32: set share flags when opening files (fixes #7494)

Rémi Denis-Courmont git at videolan.org
Thu Sep 20 18:06:10 CEST 2012


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Thu Sep 20 19:04:21 2012 +0300| [c783ea4f95070fb19c84573495b9127e95dce750] | committer: Rémi Denis-Courmont

Win32: set share flags when opening files (fixes #7494)

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=c783ea4f95070fb19c84573495b9127e95dce750
---

 src/win32/filesystem.c |   15 ++++++++++++---
 1 file changed, 12 insertions(+), 3 deletions(-)

diff --git a/src/win32/filesystem.c b/src/win32/filesystem.c
index a9d0809..0e06221 100644
--- a/src/win32/filesystem.c
+++ b/src/win32/filesystem.c
@@ -36,6 +36,7 @@
 #include <dirent.h>
 #include <sys/stat.h>
 #include <fcntl.h>
+#include <share.h>
 #include <winsock2.h>
 #include <direct.h>
 
@@ -66,7 +67,7 @@ static wchar_t *widen_path (const char *path)
 
 int vlc_open (const char *filename, int flags, ...)
 {
-    unsigned int mode = 0;
+    int share, mode;
     va_list ap;
 
     flags |= O_NOINHERIT; /* O_CLOEXEC */
@@ -74,9 +75,16 @@ int vlc_open (const char *filename, int flags, ...)
     if ((flags & O_TEXT) == 0)
         flags |= O_BINARY;
 
+    if ((flags & O_ACCMODE) == O_RDONLY || (flags & O_APPEND))
+        share = SH_DENYNO;
+    else
+        share = SH_DENYWR;
+
     va_start (ap, flags);
     if (flags & O_CREAT)
-        mode = va_arg (ap, unsigned int);
+        mode = va_arg (ap, int);
+    else
+        mode = 0;
     va_end (ap);
 
     /*
@@ -87,7 +95,8 @@ int vlc_open (const char *filename, int flags, ...)
     if (wpath == NULL)
         return -1;
 
-    int fd = _wopen (wpath, flags, mode);
+    int fd;
+    _wsopen_s (&fd, wpath, flags, share, mode);
     free (wpath);
     return fd;
 }



More information about the vlc-commits mailing list