[vlc-commits] [Git][videolan/vlc][master] 2 commits: win32/spawn: use _open directly

Steve Lhomme (@robUx4) gitlab at videolan.org
Tue Jun 24 08:48:34 UTC 2025



Steve Lhomme pushed to branch master at VideoLAN / VLC


Commits:
83f95928 by Steve Lhomme at 2025-06-24T08:24:08+00:00
win32/spawn: use _open directly

This is what vlc_open uses but we don't need to convert the string
or parse extra flags.

- - - - -
73950592 by Steve Lhomme at 2025-06-24T08:24:08+00:00
win32/filesystem: use CreateFileW with FILE_SHARE_DELETE in vlc_open()

So the file can be renamed while we read it [^1].

The file permission creation mode is not used anymore.
Only 0666 and 0600 were used.

Fixes #19700.

[^1]: https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilew#file_share_delete

- - - - -


2 changed files:

- src/win32/filesystem.c
- src/win32/spawn.c


Changes:

=====================================
src/win32/filesystem.c
=====================================
@@ -65,24 +65,46 @@ static wchar_t *widen_path (const char *path)
 
 int vlc_open (const char *filename, int flags, ...)
 {
-    int mode = 0;
-    va_list ap;
+    DWORD dwDesiredAccess, dwCreationDisposition, dwFlagsAndAttributes;
 
     flags |= O_NOINHERIT; /* O_CLOEXEC */
     /* Defaults to binary mode */
     if ((flags & O_TEXT) == 0)
         flags |= O_BINARY;
 
-    va_start (ap, flags);
+    if (flags & O_WRONLY)
+    {
+        dwDesiredAccess = GENERIC_WRITE;
+    }
+    else if (flags & O_RDWR)
+    {
+        dwDesiredAccess = GENERIC_READ | GENERIC_WRITE;
+    }
+    else // if (flags & O_RDONLY)
+    {
+        dwDesiredAccess = GENERIC_READ;
+    }
+
     if (flags & O_CREAT)
     {
-        int unixmode = va_arg(ap, int);
-        if (unixmode & 0444)
-            mode |= _S_IREAD;
-        if (unixmode & 0222)
-            mode |= _S_IWRITE;
+        if (flags & O_EXCL)
+            dwCreationDisposition = CREATE_NEW;
+        else
+            dwCreationDisposition = CREATE_ALWAYS;
     }
-    va_end (ap);
+    else if (flags & O_TRUNC)
+    {
+        dwCreationDisposition = TRUNCATE_EXISTING;
+    }
+    else
+    {
+        dwCreationDisposition = OPEN_EXISTING;
+    }
+
+    dwFlagsAndAttributes = FILE_FLAG_RANDOM_ACCESS | SECURITY_SQOS_PRESENT | SECURITY_IDENTIFICATION;
+
+    // if (flags & O_NONBLOCK)
+    //     dwFlagsAndAttributes |= FILE_FLAG_OVERLAPPED;
 
     /*
      * open() cannot open files with non-“ANSI” characters on Windows.
@@ -92,8 +114,31 @@ int vlc_open (const char *filename, int flags, ...)
     if (wpath == NULL)
         return -1;
 
-    int fd = _wopen (wpath, flags, mode);
+    HANDLE h;
+#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP)
+    h = CreateFileW(wpath, dwDesiredAccess,
+        FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
+        NULL, dwCreationDisposition,
+        dwFlagsAndAttributes, NULL);
+#else
+    CREATEFILE2_EXTENDED_PARAMETERS params = { 0 };
+    params.dwSize = sizeof(params);
+    params.dwFileAttributes = dwFlagsAndAttributes & 0xFFFF;
+    params.dwFileFlags = dwFlagsAndAttributes & ~(0xFFFF | SECURITY_VALID_SQOS_FLAGS);
+    params.dwSecurityQosFlags = dwFlagsAndAttributes & SECURITY_VALID_SQOS_FLAGS;
+    h = CreateFile2(wpath, dwDesiredAccess,
+        FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
+        dwCreationDisposition,
+        &params);
+#endif
     free (wpath);
+    if (h == INVALID_HANDLE_VALUE)
+        return -1;
+    int fd = _open_osfhandle((intptr_t)h, flags);
+    if (unlikely(fd == -1))
+    {
+        CloseHandle(h);
+    }
     return fd;
 }
 


=====================================
src/win32/spawn.c
=====================================
@@ -116,7 +116,7 @@ static int vlc_spawn_inner(pid_t *restrict pid, const char *path,
     char *cmdline = NULL;
 
     if (fdv[0] == -1 || fdv[1] == -1) {
-        nulfd = vlc_open("\\\\.\\NUL", O_RDWR);
+        nulfd = _open("\\\\.\\NUL", O_RDWR);
         if (unlikely(nulfd == -1))
             goto error;
 



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/dde35b7bd5ba1c0430b91fd4c129fc1d4e2932ea...73950592f883ff237173837c5574416cb3d0beec

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/dde35b7bd5ba1c0430b91fd4c129fc1d4e2932ea...73950592f883ff237173837c5574416cb3d0beec
You're receiving this email because of your account on code.videolan.org.


VideoLAN code repository instance


More information about the vlc-commits mailing list