[vlc-commits] Revert "win32 opendir: remove broken and obsolete special mode"

Jean-Baptiste Kempf git at videolan.org
Fri Aug 16 11:09:13 CEST 2013


vlc/vlc-2.1 | branch: master | Jean-Baptiste Kempf <jb at videolan.org> | Fri Aug 16 10:59:17 2013 +0200| [208263b3c60c50bc26f83b94cc1037c902bc7a82] | committer: Jean-Baptiste Kempf

Revert "win32 opendir: remove broken and obsolete special mode"

This reverts commit 5bb66d739c32023b033c6fde0cd7c807493f4fbf.

(cherry picked from commit 5d7ac19898a7bd54d20ac500d318c8f0b5f36051)
Signed-off-by: Jean-Baptiste Kempf <jb at videolan.org>

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

 src/win32/filesystem.c |   40 ++++++++++++++++++++++++++++++++++++----
 1 file changed, 36 insertions(+), 4 deletions(-)

diff --git a/src/win32/filesystem.c b/src/win32/filesystem.c
index f20f7e4..e1317a4 100644
--- a/src/win32/filesystem.c
+++ b/src/win32/filesystem.c
@@ -127,7 +127,11 @@ char *vlc_getcwd (void)
 typedef struct vlc_DIR
 {
     _WDIR *wdir; /* MUST be first, see <vlc_fs.h> */
-    bool insert_dot_dot;
+    union
+    {
+        DWORD drives;
+        bool insert_dot_dot;
+    } u;
 } vlc_DIR;
 
 
@@ -144,8 +148,17 @@ DIR *vlc_opendir (const char *dirname)
         return NULL;
     }
 
+    if (wpath[0] == L'\0' || (wcscmp (wpath, L"\\") == 0))
+    {
+        free (wpath);
+        /* Special mode to list drive letters */
+        p_dir->wdir = NULL;
+        p_dir->u.drives = GetLogicalDrives ();
+        return (void *)p_dir;
+    }
+
     assert (wpath[0]); // wpath[1] is defined
-    p_dir->insert_dot_dot = !wcscmp (wpath + 1, L":\\");
+    p_dir->u.insert_dot_dot = !wcscmp (wpath + 1, L":\\");
 
     _WDIR *wdir = _wopendir (wpath);
     free (wpath);
@@ -162,10 +175,29 @@ char *vlc_readdir (DIR *dir)
 {
     vlc_DIR *p_dir = (vlc_DIR *)dir;
 
-    if (p_dir->insert_dot_dot)
+    if (p_dir->wdir == NULL)
+    {
+        /* Drive letters mode */
+        DWORD drives = p_dir->u.drives;
+        if (drives == 0)
+            return NULL; /* end */
+
+        unsigned int i;
+        for (i = 0; !(drives & 1); i++)
+            drives >>= 1;
+        p_dir->u.drives &= ~(1UL << i);
+        assert (i < 26);
+
+        char *ret;
+        if (asprintf (&ret, "%c:\\", 'A' + i) == -1)
+            return NULL;
+        return ret;
+    }
+
+    if (p_dir->u.insert_dot_dot)
     {
         /* Adds "..", gruik! */
-        p_dir->insert_dot_dot = false;
+        p_dir->u.insert_dot_dot = false;
         return strdup ("..");
     }
 



More information about the vlc-commits mailing list