[vlc-commits] [Git][videolan/vlc][master] 3 commits: win32: filesystem: don't add backslash on folder search if it ends with one

Rémi Denis-Courmont (@Courmisch) gitlab at videolan.org
Sun Aug 14 07:22:48 UTC 2022



Rémi Denis-Courmont pushed to branch master at VideoLAN / VLC


Commits:
a716e84a by Steve Lhomme at 2022-08-14T06:55:33+00:00
win32: filesystem: don't add backslash on folder search if it ends with one

- - - - -
c10ea848 by Steve Lhomme at 2022-08-14T06:55:33+00:00
win32: filesystem: optimize the folder search string creation

We can tell the end size faster than asprintf and replace the forward slash
while filling the output string. (it is safe to replace in a UTF-8 string).

- - - - -
cd238cef by Steve Lhomme at 2022-08-14T06:55:33+00:00
win32: use the proper backslash in Windows pathes (bis)

Similar to dec06aeca77546a404461dab98391e1ff2c58816 for UAP builds.

- - - - -


2 changed files:

- src/win32/dirs-uap.c
- src/win32/filesystem.c


Changes:

=====================================
src/win32/dirs-uap.c
=====================================
@@ -152,7 +152,7 @@ char *config_GetSysPath(vlc_sysdir_t type, const char *filename)
         return dir;
 
     char *path;
-    if (unlikely(asprintf(&path, "%s/%s", dir, filename) == -1))
+    if (unlikely(asprintf(&path, "%s\\%s", dir, filename) == -1))
         path = NULL;
     free(dir);
     return path;


=====================================
src/win32/filesystem.c
=====================================
@@ -211,16 +211,55 @@ vlc_DIR *vlc_opendir (const char *dirname)
     p_dir->u.insert_dot_dot = !strcmp (dirname + 1, ":\\");
 
     char *wildcard;
-    int res;
+    const size_t len = strlen(dirname);
     if (p_dir->u.insert_dot_dot)
+    {
         // Prepending the string "\\?\" does not allow access to the root directory.
-        res = asprintf(&wildcard, "%s\\*", dirname);
+        wildcard = malloc(len + 3);
+        if (unlikely(wildcard == NULL))
+        {
+            free (p_dir);
+            return NULL;
+        }
+        else
+        {
+            memcpy(wildcard, dirname, len);
+            size_t j = len;
+            wildcard[j++] = '\\';
+            wildcard[j++] = '*';
+            wildcard[j++] = '\0';
+        }
+    }
     else
-        res = asprintf(&wildcard, "\\\\?\\%s\\*", dirname);
-    if (res < 0)
     {
-        free (p_dir);
-        return NULL;
+        wildcard = malloc(4 + len + 3);
+        if (unlikely(wildcard == NULL))
+        {
+            free (p_dir);
+            return NULL;
+        }
+        else
+        {
+            // prepend "\\?\"
+            wildcard[0] = '\\';
+            wildcard[1] = '\\';
+            wildcard[2] = '?';
+            wildcard[3] = '\\';
+            size_t j = 4;
+            for (size_t i=0; i<len;i++)
+            {
+                // remove forward slashes from long pathes to please FindFirstFileExW
+                if (unlikely(dirname[i] == '/'))
+                    wildcard[j++] = '\\';
+                else
+                    wildcard[j++] = dirname[i];
+            }
+            // append "\*" or "*"
+            if (wildcard[j-1] != '\\')
+                wildcard[j++] = '\\';
+            wildcard[j++] = '*';
+            wildcard[j++] = '\0';
+        }
     }
     p_dir->wildcard = ToWide(wildcard);
     free(wildcard);
@@ -229,15 +268,6 @@ vlc_DIR *vlc_opendir (const char *dirname)
         free (p_dir);
         return NULL;
     }
-    if (!p_dir->u.insert_dot_dot)
-    {
-        // remove forward slashes from long pathes to please FindFirstFileExW
-        for (size_t i=0; p_dir->wildcard[i]!=L'\0';i++)
-        {
-            if (unlikely(p_dir->wildcard[i] == L'/'))
-                p_dir->wildcard[i] = L'\\';
-        }
-    }
 
     p_dir->fHandle = FindFirstFileExW(p_dir->wildcard, FindExInfoBasic,
                                       &p_dir->wdir, (FINDEX_SEARCH_OPS)0,



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/6dea7695a5f97206c82f64757e1e7c7ce9b45ebf...cd238cef65cdebc09a6a8ed0407f47b4749c1c60

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/6dea7695a5f97206c82f64757e1e7c7ce9b45ebf...cd238cef65cdebc09a6a8ed0407f47b4749c1c60
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