[vlc-commits] [Git][videolan/vlc][master] 20 commits: snapshot: remove unused dirent include

Hugo Beauzée-Luyssen (@chouquette) gitlab at videolan.org
Wed Aug 3 12:04:42 UTC 2022



Hugo Beauzée-Luyssen pushed to branch master at VideoLAN / VLC


Commits:
82b9e5f1 by Steve Lhomme at 2022-08-03T11:44:10+00:00
snapshot: remove unused dirent include

We don't use any DIR API.

- - - - -
b578d8e7 by Steve Lhomme at 2022-08-03T11:44:10+00:00
darwin: remove unused dirent include

We don't use any DIR API.

- - - - -
a7b090d3 by Steve Lhomme at 2022-08-03T11:44:10+00:00
access: file: remove direct dirent.h include

It's included when necessary in vlc_fs.h

- - - - -
30375359 by Steve Lhomme at 2022-08-03T11:44:10+00:00
vlc_fs: add vlc_closedir/vlc_rewinddir for all platforms

To have a cleaner balance between the directory API calls.

- - - - -
63d09289 by Steve Lhomme at 2022-08-03T11:44:10+00:00
dcp: use the portable opendir API

We have a portable way to list entries in a directory.

- - - - -
62c6b3d7 by Steve Lhomme at 2022-08-03T11:44:10+00:00
skins2: use the portable opendir API

- - - - -
fbb6f140 by Steve Lhomme at 2022-08-03T11:44:10+00:00
modules: use vlc_closedir instead of direct closedir

So it matches vlc_opendir() calls.

- - - - -
f52bf066 by Steve Lhomme at 2022-08-03T11:44:10+00:00
core: use vlc_closedir instead of direct closedir

So it matches vlc_opendir() calls.

- - - - -
d19b32ac by Steve Lhomme at 2022-08-03T11:44:10+00:00
core: use vlc_rewinddir to match vlc_opendir

- - - - -
92240d23 by Steve Lhomme at 2022-08-03T11:44:10+00:00
vlc_fs: move up vlc_DIR declaration

No functional changes.

- - - - -
4862e419 by Steve Lhomme at 2022-08-03T11:44:10+00:00
vlc_fs: always use a custom type for our opendir API's

This will avoid some dirty casts between DIR and vlc_DIR on Windows.

The Windows handling could be done entirely without dirent.h which is not a
standard Windows API.

- - - - -
ab47fa08 by Steve Lhomme at 2022-08-03T11:44:10+00:00
win32: filesystem: allow GetLogicalDrives() in Win10 RS3 UAP builds

- - - - -
5c72b261 by Steve Lhomme at 2022-08-03T11:44:10+00:00
win32: filesystem: only convert to wide when necessary

- - - - -
e0efe396 by Steve Lhomme at 2022-08-03T11:44:10+00:00
win32: filesystem: initialize entry once

- - - - -
d91f33c2 by Steve Lhomme at 2022-08-03T11:44:10+00:00
win32: filesystem: check the drive letter bitmask is valid

- - - - -
15b65c60 by Steve Lhomme at 2022-08-03T11:44:10+00:00
win32: filesystem: use the native Win32 API to list folder contents

The API is available on UWP builds and doesn't rely on dirent which may not be
compiled as UNICODE in mingw-w64.

The call to FindFirstFileExW already gets the first entry so we are always
ahead of one entry.

- - - - -
b95df4e1 by Steve Lhomme at 2022-08-03T11:44:10+00:00
vlc_fs: export vlc_closedir/vlc_rewinddir

So it matches the other exports

- - - - -
d57b9a4c by Steve Lhomme at 2022-08-03T11:44:10+00:00
vlc_fs: make the internal vlc_DIR type private on Windows

- - - - -
9df66662 by Steve Lhomme at 2022-08-03T11:44:10+00:00
win32: filesystem: reuse the drive string

No need to use asprint to fill a character at a fixed location on a fixed size
string.

- - - - -
2d8beeb2 by Steve Lhomme at 2022-08-03T11:44:10+00:00
win32: filesystem: allow access to very long folder names

Prepending \\?\ allow much longer input pathes
https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-findfirstfileexw

This is not possible with mingw-w64 implementation of opendir/readdir.

- - - - -


23 changed files:

- include/vlc_fs.h
- modules/access/dcp/dcp.cpp
- modules/access/directory.c
- modules/access/file.c
- modules/access/fs.h
- modules/demux/mkv/mkv.cpp
- modules/gui/ncurses.c
- modules/gui/skins2/os2/os2_factory.cpp
- modules/gui/skins2/src/theme_loader.cpp
- modules/gui/skins2/src/theme_repository.cpp
- modules/gui/skins2/x11/x11_factory.cpp
- modules/lua/libs/io.c
- modules/lua/libs/net.c
- src/darwin/specific.c
- src/input/subtitles.c
- src/libvlccore.sym
- src/modules/bank.c
- src/os2/filesystem.c
- src/posix/filesystem.c
- src/preparser/art.c
- src/text/filesystem.c
- src/video_output/snapshot.c
- src/win32/filesystem.c


Changes:

=====================================
include/vlc_fs.h
=====================================
@@ -22,12 +22,12 @@
 #define VLC_FS_H 1
 
 #include <sys/types.h>
-#include <dirent.h>
 
 struct stat;
 struct iovec;
 
 #ifdef _WIN32
+# include <io.h>
 # include <sys/stat.h>
 # ifndef stat
 #  define stat _stati64
@@ -39,6 +39,8 @@ struct iovec;
 #  undef lseek
 #  define lseek _lseeki64
 # endif
+#else // !_WIN32
+#include <dirent.h>
 #endif
 
 #ifdef __ANDROID__
@@ -229,14 +231,20 @@ VLC_API FILE * vlc_fopen( const char *filename, const char *mode ) VLC_USED;
  * @{
  */
 
+#if defined( _WIN32 )
+typedef struct vlc_DIR vlc_DIR;
+#else // !_WIN32
+typedef DIR vlc_DIR;
+#endif
+
 /**
  * Opens a DIR pointer.
  *
  * @param dirname UTF-8 representation of the directory name
  * @return a pointer to the DIR struct, or NULL in case of error.
- * Release with standard closedir().
+ * Release with vlc_closedir().
  */
-VLC_API DIR *vlc_opendir(const char *dirname) VLC_USED;
+VLC_API vlc_DIR *vlc_opendir(const char *dirname) VLC_USED;
 
 /**
  * Reads the next file name from an open directory.
@@ -245,15 +253,18 @@ VLC_API DIR *vlc_opendir(const char *dirname) VLC_USED;
  *            (must not be used by another thread concurrently)
  *
  * @return a UTF-8 string of the directory entry. The string is valid until
- * the next call to vlc_readdir() or closedir() on the handle.
+ * the next call to vlc_readdir() or vlc_closedir() on the handle.
  * If there are no more entries in the directory, NULL is returned.
  * If an error occurs, errno is set and NULL is returned.
  */
-VLC_API const char *vlc_readdir(DIR *dir) VLC_USED;
+VLC_API const char *vlc_readdir(vlc_DIR *dir) VLC_USED;
 
-VLC_API int vlc_loaddir( DIR *dir, char ***namelist, int (*select)( const char * ), int (*compar)( const char **, const char ** ) );
+VLC_API int vlc_loaddir( vlc_DIR *dir, char ***namelist, int (*select)( const char * ), int (*compar)( const char **, const char ** ) );
 VLC_API int vlc_scandir( const char *dirname, char ***namelist, int (*select)( const char * ), int (*compar)( const char **, const char ** ) );
 
+VLC_API void vlc_closedir( vlc_DIR *dir );
+VLC_API void vlc_rewinddir( vlc_DIR *dir );
+
 /**
  * Creates a directory.
  *
@@ -274,40 +285,6 @@ VLC_API char *vlc_getcwd(void) VLC_USED;
 
 /** @} */
 
-#if defined( _WIN32 )
-typedef struct vlc_DIR
-{
-    _WDIR *wdir; /* MUST be first, see <vlc_fs.h> */
-    char *entry;
-    union
-    {
-        DWORD drives;
-        bool insert_dot_dot;
-    } u;
-} vlc_DIR;
-
-static inline int vlc_closedir( DIR *dir )
-{
-    vlc_DIR *vdir = (vlc_DIR *)dir;
-    _WDIR *wdir = vdir->wdir;
-
-    free( vdir->entry );
-    free( vdir );
-    return (wdir != NULL) ? _wclosedir( wdir ) : 0;
-}
-# undef closedir
-# define closedir vlc_closedir
-
-static inline void vlc_rewinddir( DIR *dir )
-{
-    _WDIR *wdir = *(_WDIR **)dir;
-
-    _wrewinddir( wdir );
-}
-# undef rewinddir
-# define rewinddir vlc_rewinddir
-#endif
-
 #ifdef __ANDROID__
 # define lseek lseek64
 #endif


=====================================
modules/access/dcp/dcp.cpp
=====================================
@@ -50,6 +50,7 @@
 #include <vlc_xml.h>
 #include <vlc_url.h>
 #include <vlc_aout.h>
+#include <vlc_fs.h>
 
 #ifdef _WIN32
 # define KM_WIN32
@@ -956,26 +957,26 @@ int dcpInit ( demux_t *p_demux )
  */
 static std::string assetmapPath( demux_t * p_demux )
 {
-    DIR *dir = NULL;
-    struct dirent *ent = NULL;
+    vlc_DIR *dir = NULL;
+    const char *ent = NULL;
     demux_sys_t *p_sys = (demux_sys_t *)p_demux->p_sys;
     dcp_t *p_dcp = p_sys->p_dcp;
     std::string result;
 
-    if( ( dir = opendir (p_dcp->path.c_str() ) ) != NULL )
+    if( ( dir = vlc_opendir (p_dcp->path.c_str() ) ) != NULL )
     {
         /* print all the files and directories within directory */
-        while( ( ent = readdir ( dir ) ) != NULL )
+        while( ( ent = vlc_readdir ( dir ) ) != NULL )
         {
-            if( strcasecmp( "assetmap", ent->d_name ) == 0 || strcasecmp( "assetmap.xml", ent->d_name ) == 0 )
+            if( strcasecmp( "assetmap", ent ) == 0 || strcasecmp( "assetmap.xml", ent ) == 0 )
             {
                 /* copy of "path" in "res" */
                 result = p_dcp->path;
-                result.append( ent->d_name );
+                result.append( ent );
                 break;
             }
         }
-        closedir( dir );
+        vlc_closedir( dir );
     }
     else
         msg_Err( p_demux, "Could not open the directory: %s", p_dcp->path.c_str() );


=====================================
modules/access/directory.c
=====================================
@@ -45,7 +45,7 @@ typedef struct
 {
     char *base_uri;
     bool need_separator;
-    DIR *dir;
+    vlc_DIR *dir;
 } access_sys_t;
 
 static int DirRead (stream_t *access, input_item_node_t *node);
@@ -67,7 +67,7 @@ static int DirControl( stream_t *p_access, int i_query, va_list args )
 /*****************************************************************************
  * DirInit: Init the directory access with a directory stream
  *****************************************************************************/
-int DirInit (stream_t *access, DIR *dir)
+int DirInit (stream_t *access, vlc_DIR *dir)
 {
     access_sys_t *sys = vlc_obj_malloc(VLC_OBJECT(access), sizeof (*sys));
     if (unlikely(sys == NULL))
@@ -98,7 +98,7 @@ int DirInit (stream_t *access, DIR *dir)
     return VLC_SUCCESS;
 
 error:
-    closedir(dir);
+    vlc_closedir(dir);
     return VLC_ENOMEM;
 }
 
@@ -112,7 +112,7 @@ int DirOpen (vlc_object_t *obj)
     if (access->psz_filepath == NULL)
         return VLC_EGENERIC;
 
-    DIR *dir = vlc_opendir(access->psz_filepath);
+    vlc_DIR *dir = vlc_opendir(access->psz_filepath);
     if (dir == NULL)
         return VLC_EGENERIC;
 
@@ -128,7 +128,7 @@ void DirClose(vlc_object_t *obj)
     access_sys_t *sys = access->p_sys;
 
     free(sys->base_uri);
-    closedir(sys->dir);
+    vlc_closedir(sys->dir);
 }
 
 static int DirRead (stream_t *access, input_item_node_t *node)


=====================================
modules/access/file.c
=====================================
@@ -53,7 +53,6 @@
 #else
 #   include <unistd.h>
 #endif
-#include <dirent.h>
 
 #include <vlc_common.h>
 #include "fs.h"


=====================================
modules/access/fs.h
=====================================
@@ -18,11 +18,11 @@
  * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
  *****************************************************************************/
 
-#include <dirent.h>
+#include <vlc_fs.h>
 
 int FileOpen (vlc_object_t *);
 void FileClose (vlc_object_t *);
 
 int DirOpen (vlc_object_t *);
-int DirInit (stream_t *p_access, DIR *handle);
+int DirInit (stream_t *p_access, vlc_DIR *handle);
 void DirClose (vlc_object_t *);


=====================================
modules/demux/mkv/mkv.cpp
=====================================
@@ -185,7 +185,7 @@ static int OpenInternal( demux_t *p_demux, bool trust_cues )
                 }
             }
 
-            DIR *p_src_dir = vlc_opendir(s_path.c_str());
+            vlc_DIR *p_src_dir = vlc_opendir(s_path.c_str());
 
             if (p_src_dir != NULL)
             {
@@ -245,7 +245,7 @@ static int OpenInternal( demux_t *p_demux, bool trust_cues )
                         }
                     }
                 }
-                closedir( p_src_dir );
+                vlc_closedir( p_src_dir );
             }
         }
 


=====================================
modules/gui/ncurses.c
=====================================
@@ -272,7 +272,7 @@ static void ReadDir(intf_thread_t *intf)
         return;
     }
 
-    DIR *current_dir = vlc_opendir(sys->current_dir);
+    vlc_DIR *current_dir = vlc_opendir(sys->current_dir);
     if (!current_dir) {
         msg_Warn(intf, "cannot open directory `%s' (%s)", sys->current_dir,
                  vlc_strerror_c(errno));
@@ -301,7 +301,7 @@ static void ReadDir(intf_thread_t *intf)
         continue;
     }
 
-    closedir(current_dir);
+    vlc_closedir(current_dir);
 
     if (sys->n_dir_entries > 0)
         qsort(sys->dir_entries, sys->n_dir_entries,


=====================================
modules/gui/skins2/os2/os2_factory.cpp
=====================================
@@ -426,17 +426,17 @@ void OS2Factory::changeCursor( CursorType_t type ) const
 
 void OS2Factory::rmDir( const std::string &rPath )
 {
-    struct dirent *file;
-    DIR *dir;
+    const char *file;
+    vlc_DIR *dir;
 
-    dir = opendir( rPath.c_str() );
+    dir = vlc_opendir( rPath.c_str() );
     if( !dir ) return;
 
     // Parse the directory and remove everything it contains
-    while( (file = readdir( dir )) )
+    while( (file = vlc_readdir( dir )) )
     {
         struct stat statbuf;
-        std::string filename = file->d_name;
+        std::string filename = file;
 
         // Skip "." and ".."
         if( filename == "." || filename == ".." )
@@ -457,7 +457,7 @@ void OS2Factory::rmDir( const std::string &rPath )
     }
 
     // Close the directory
-    closedir( dir );
+    vlc_closedir( dir );
 
     // And delete it
     rmdir( rPath.c_str() );


=====================================
modules/gui/skins2/src/theme_loader.cpp
=====================================
@@ -344,7 +344,7 @@ bool ThemeLoader::findFile( const std::string &rootDir, const std::string &rFile
     const char *pszDirContent;
 
     // Open the dir
-    DIR *pCurrDir = vlc_opendir( rootDir.c_str() );
+    vlc_DIR *pCurrDir = vlc_opendir( rootDir.c_str() );
 
     if( pCurrDir == NULL )
     {
@@ -376,7 +376,7 @@ bool ThemeLoader::findFile( const std::string &rootDir, const std::string &rFile
                 // Can we find the file in this subdirectory?
                 if( findFile( newURI, rFileName, themeFilePath ) )
                 {
-                    closedir( pCurrDir );
+                    vlc_closedir( pCurrDir );
                     return true;
                 }
             }
@@ -386,14 +386,14 @@ bool ThemeLoader::findFile( const std::string &rootDir, const std::string &rFile
                 if( rFileName == std::string( pszDirContent ) )
                 {
                     themeFilePath = newURI;
-                    closedir( pCurrDir );
+                    vlc_closedir( pCurrDir );
                     return true;
                 }
             }
         }
     }
 
-    closedir( pCurrDir );
+    vlc_closedir( pCurrDir );
     return false;
 }
 


=====================================
modules/gui/skins2/src/theme_repository.cpp
=====================================
@@ -138,7 +138,7 @@ void ThemeRepository::parseDirectory( const std::string &rDir )
     const std::string &sep = OSFactory::instance( getIntf() )->getDirSeparator();
 
     // Open the dir
-    DIR *pDir = vlc_opendir( rDir.c_str() );
+    vlc_DIR *pDir = vlc_opendir( rDir.c_str() );
     if( pDir == NULL )
     {
         // An error occurred
@@ -169,7 +169,7 @@ void ThemeRepository::parseDirectory( const std::string &rDir )
         }
     }
 
-    closedir( pDir );
+    vlc_closedir( pDir );
 }
 
 


=====================================
modules/gui/skins2/x11/x11_factory.cpp
=====================================
@@ -25,7 +25,6 @@
 
 #include <errno.h>
 #include <unistd.h>
-#include <dirent.h>
 #include <X11/Xlib.h>
 #include <X11/extensions/Xinerama.h>
 
@@ -373,16 +372,16 @@ void X11Factory::getMousePos( int &rXPos, int &rYPos ) const
 
 void X11Factory::rmDir( const std::string &rPath )
 {
-    struct dirent *file;
-    DIR *dir;
+    const char *file;
+    vlc_DIR *dir;
 
-    dir = opendir( rPath.c_str() );
+    dir = vlc_opendir( rPath.c_str() );
     if( !dir ) return;
 
     // Parse the directory and remove everything it contains
-    while( (file = readdir( dir )) )
+    while( (file = vlc_readdir( dir )) )
     {
-        std::string filename = file->d_name;
+        std::string filename = file;
 
         // Skip "." and ".."
         if( filename == "." || filename == ".." )
@@ -397,7 +396,7 @@ void X11Factory::rmDir( const std::string &rPath )
     }
 
     // Close the directory
-    closedir( dir );
+    vlc_closedir( dir );
 
     // And delete it
     rmdir( rPath.c_str() );


=====================================
modules/lua/libs/io.c
=====================================
@@ -213,7 +213,7 @@ static int vlclua_io_readdir( lua_State *L )
     if( lua_gettop( L ) < 1 )
         return luaL_error( L, "Usage: vlc.io.readdir(name)" );
     const char* psz_path = luaL_checkstring( L, 1 );
-    DIR* p_dir =  vlc_opendir( psz_path );
+    vlc_DIR* p_dir =  vlc_opendir( psz_path );
     if ( p_dir == NULL )
         return 0;
 
@@ -226,7 +226,7 @@ static int vlclua_io_readdir( lua_State *L )
         lua_rawseti( L, -2, idx );
         idx++;
     }
-    closedir( p_dir );
+    vlc_closedir( p_dir );
     return 1;
 }
 


=====================================
modules/lua/libs/net.c
=====================================
@@ -441,7 +441,7 @@ static int vlclua_stat( lua_State *L )
 static int vlclua_opendir( lua_State *L )
 {
     const char *psz_dir = luaL_checkstring( L, 1 );
-    DIR *p_dir;
+    vlc_DIR *p_dir;
     int i = 0;
 
     if( ( p_dir = vlc_opendir( psz_dir ) ) == NULL )
@@ -456,7 +456,7 @@ static int vlclua_opendir( lua_State *L )
         lua_pushstring( L, psz_filename );
         lua_rawseti( L, -2, i );
     }
-    closedir( p_dir );
+    vlc_closedir( p_dir );
     return 1;
 }
 


=====================================
src/darwin/specific.c
=====================================
@@ -29,7 +29,6 @@
 
 #include <vlc_common.h>
 #include "../libvlc.h"
-#include <dirent.h>                                                /* *dir() */
 #include <CoreFoundation/CoreFoundation.h>
 
 #include <locale.h>


=====================================
src/input/subtitles.c
=====================================
@@ -57,10 +57,10 @@ static void filename_strip_ext_inplace(char *str)
 
 /**
  * Trim special characters from a filename
- * 
+ *
  * Trims whitespaces and other non-alphanumeric
  * characters from filenames.
- * 
+ *
  * \warning This function operates on the passed string
  * without copying. It might return a pointer different to
  * the passed one, in case it trims characters at the beginning.
@@ -262,7 +262,7 @@ int subtitles_Detect( input_thread_t *p_this, char *psz_path, const char *psz_na
             continue;
 
         /* parse psz_src dir */
-        DIR *dir = vlc_opendir( psz_dir );
+        vlc_DIR *dir = vlc_opendir( psz_dir );
         if( dir == NULL )
             continue;
 
@@ -352,7 +352,7 @@ int subtitles_Detect( input_thread_t *p_this, char *psz_path, const char *psz_na
                 free( path );
             }
         }
-        closedir( dir );
+        vlc_closedir( dir );
     }
     if( subdirs )
     {


=====================================
src/libvlccore.sym
=====================================
@@ -449,6 +449,8 @@ vlc_memfd
 vlc_opendir
 vlc_readdir
 vlc_scandir
+vlc_closedir
+vlc_rewinddir
 vlc_stat
 vlc_strcasestr
 vlc_unlink


=====================================
src/modules/bank.c
=====================================
@@ -422,7 +422,7 @@ static void AllocatePluginDir (module_bank_t *bank, unsigned maxdepth,
         return;
     maxdepth--;
 
-    DIR *dh = vlc_opendir (absdir);
+    vlc_DIR *dh = vlc_opendir (absdir);
     if (dh == NULL)
         return;
 
@@ -502,7 +502,7 @@ static void AllocatePluginDir (module_bank_t *bank, unsigned maxdepth,
         free (relpath);
         free (abspath);
     }
-    closedir (dh);
+    vlc_closedir (dh);
 }
 
 /**


=====================================
src/os2/filesystem.c
=====================================
@@ -123,6 +123,11 @@ DIR *vlc_opendir (const char *dirname)
     return dir;
 }
 
+void vlc_closedir(DIR *dir)
+{
+    closedir(dir);
+}
+
 const char *vlc_readdir(DIR *dir)
 {
     /* Beware that readdir_r() assumes <buf> is large enough to hold the result
@@ -155,6 +160,11 @@ const char *vlc_readdir(DIR *dir)
     return path;
 }
 
+void vlc_rewinddir(DIR *dir)
+{
+    rewinddir(dir);
+}
+
 static int vlc_statEx (const char *filename, struct stat *buf, bool deref)
 {
     const char *local_name = ToLocaleDup (filename);


=====================================
src/posix/filesystem.c
=====================================
@@ -126,12 +126,22 @@ DIR *vlc_opendir (const char *dirname)
     return opendir (dirname);
 }
 
+void vlc_closedir(DIR *dir)
+{
+    closedir(dir);
+}
+
 const char *vlc_readdir(DIR *dir)
 {
     struct dirent *ent = readdir (dir);
     return (ent != NULL) ? ent->d_name : NULL;
 }
 
+void vlc_rewinddir(DIR *dir)
+{
+    rewinddir(dir);
+}
+
 int vlc_stat (const char *filename, struct stat *buf)
 {
     return stat (filename, buf);


=====================================
src/preparser/art.c
=====================================
@@ -185,7 +185,7 @@ int input_FindArtInCache( input_item_t *p_item )
         return VLC_EGENERIC;
 
     /* Check if file exists */
-    DIR *p_dir = vlc_opendir( psz_path );
+    vlc_DIR *p_dir = vlc_opendir( psz_path );
     if( !p_dir )
     {
         free( psz_path );
@@ -216,7 +216,7 @@ int input_FindArtInCache( input_item_t *p_item )
     }
 
     /* */
-    closedir( p_dir );
+    vlc_closedir( p_dir );
     free( psz_path );
     return b_found ? VLC_SUCCESS : VLC_EGENERIC;
 }


=====================================
src/text/filesystem.c
=====================================
@@ -118,7 +118,7 @@ static int compar_void(const void *a, const void *b, void *data)
  * Does the same as vlc_scandir(), but takes an open directory pointer
  * instead of a directory path.
  */
-int vlc_loaddir( DIR *dir, char ***namelist,
+int vlc_loaddir( vlc_DIR *dir, char ***namelist,
                   int (*select)( const char * ),
                   int (*compar)( const char **, const char ** ) )
 {
@@ -130,7 +130,7 @@ int vlc_loaddir( DIR *dir, char ***namelist,
     char **tab = NULL;
     unsigned num = 0;
 
-    rewinddir (dir);
+    vlc_rewinddir (dir);
 
     for (unsigned size = 0;;)
     {
@@ -188,13 +188,13 @@ int vlc_scandir( const char *dirname, char ***namelist,
                   int (*select)( const char * ),
                   int (*compar)( const char **, const char ** ) )
 {
-    DIR *dir = vlc_opendir (dirname);
+    vlc_DIR *dir = vlc_opendir (dirname);
     int val = -1;
 
     if (dir != NULL)
     {
         val = vlc_loaddir (dir, namelist, select, compar);
-        closedir (dir);
+        vlc_closedir (dir);
     }
     return val;
 }


=====================================
src/video_output/snapshot.c
=====================================
@@ -28,7 +28,6 @@
 #include <assert.h>
 #include <sys/stat.h>
 #include <sys/types.h>
-#include <dirent.h>
 #include <time.h>
 
 #include <vlc_common.h>


=====================================
src/win32/filesystem.c
=====================================
@@ -33,7 +33,6 @@
 #include <stdio.h>
 #include <errno.h>
 #include <sys/types.h>
-#include <dirent.h>
 #include <sys/stat.h>
 #include <fcntl.h>
 #include <winsock2.h>
@@ -49,6 +48,10 @@
 # include <io.h> /* _pipe */
 #endif
 
+#ifndef NTDDI_WIN10_RS3
+#define NTDDI_WIN10_RS3  0x0A000004
+#endif
+
 static wchar_t *widen_path (const char *path)
 {
     wchar_t *wpath;
@@ -157,62 +160,107 @@ char *vlc_getcwd (void)
 #endif
 }
 
+struct vlc_DIR
+{
+    wchar_t *wildcard;
+    HANDLE fHandle;
+    WIN32_FIND_DATAW wdir;
+    bool eol;
+
+    char *entry;
+    union
+    {
+        DWORD drives;
+        bool insert_dot_dot;
+    } u;
+};
+
 /* Under Windows, these wrappers return the list of drive letters
  * when called with an empty argument or just '\'. */
-DIR *vlc_opendir (const char *dirname)
+vlc_DIR *vlc_opendir (const char *dirname)
 {
-    wchar_t *wpath = widen_path (dirname);
-    if (wpath == NULL)
-        return NULL;
-
     vlc_DIR *p_dir = malloc (sizeof (*p_dir));
     if (unlikely(p_dir == NULL))
-    {
-        free(wpath);
         return NULL;
-    }
+    p_dir->entry = NULL;
+    p_dir->eol = false;
+    p_dir->fHandle = INVALID_HANDLE_VALUE;
+    p_dir->wildcard = NULL;
 
-#ifndef VLC_WINSTORE_APP
+#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) || NTDDI_VERSION >= NTDDI_WIN10_RS3
     /* Special mode to list drive letters */
-    if (wpath[0] == L'\0' || (wcscmp (wpath, L"\\") == 0))
+    if (dirname[0] == '\0' || (strcmp (dirname, "\\") == 0))
     {
-        free (wpath);
-        p_dir->wdir = NULL;
         p_dir->u.drives = GetLogicalDrives ();
-        p_dir->entry = NULL;
-        return (void *)p_dir;
+        if (unlikely(p_dir->u.drives == 0))
+        {
+            free(p_dir);
+            return NULL;
+        }
+        p_dir->entry = strdup("C:\\");
+        if (unlikely(p_dir->entry == NULL))
+        {
+            free(p_dir);
+            return NULL;
+        }
+        return p_dir;
     }
 #endif
 
-    assert (wpath[0]); // wpath[1] is defined
-    p_dir->u.insert_dot_dot = !wcscmp (wpath + 1, L":\\");
+    assert (dirname[0]); // dirname[1] is defined
+    p_dir->u.insert_dot_dot = !strcmp (dirname + 1, ":\\");
 
-    _WDIR *wdir = _wopendir (wpath);
-    free (wpath);
-    if (wdir == NULL)
+    char *wildcard;
+    int res;
+    if (p_dir->u.insert_dot_dot)
+        // Prepending the string "\\?\" does not allow access to the root directory.
+        res = asprintf(&wildcard, "%s\\*", dirname);
+    else
+        res = asprintf(&wildcard, "\\\\?\\%s\\*", dirname);
+    if (res < 0)
     {
         free (p_dir);
         return NULL;
     }
-    p_dir->wdir = wdir;
-    p_dir->entry = NULL;
-    return (void *)p_dir;
+    p_dir->wildcard = ToWide(wildcard);
+    free(wildcard);
+    if (unlikely(p_dir->wildcard == NULL))
+    {
+        free (p_dir);
+        return NULL;
+    }
+
+    p_dir->fHandle = FindFirstFileExW(p_dir->wildcard, FindExInfoBasic,
+                                      &p_dir->wdir, (FINDEX_SEARCH_OPS)0,
+                                      NULL, FIND_FIRST_EX_LARGE_FETCH);
+    if (p_dir->fHandle ==  INVALID_HANDLE_VALUE)
+    {
+        free(p_dir->wildcard);
+        free(p_dir);
+        return NULL;
+    }
+    return p_dir;
 }
 
-const char *vlc_readdir (DIR *dir)
+void vlc_closedir( vlc_DIR *vdir )
 {
-    vlc_DIR *p_dir = (vlc_DIR *)dir;
+    if (vdir->fHandle != INVALID_HANDLE_VALUE)
+        FindClose(vdir->fHandle);
 
-    free(p_dir->entry);
+    free( vdir->entry );
+    free( vdir->wildcard );
+    free( vdir );
+}
 
-#ifndef VLC_WINSTORE_APP
+const char *vlc_readdir (vlc_DIR *p_dir)
+{
+#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_DESKTOP) || NTDDI_VERSION >= NTDDI_WIN10_RS3
     /* Drive letters mode */
-    if (p_dir->wdir == NULL)
+    if (p_dir->fHandle ==  INVALID_HANDLE_VALUE)
     {
         DWORD drives = p_dir->u.drives;
         if (drives == 0)
         {
-            p_dir->entry = NULL;
             return NULL; /* end */
         }
 
@@ -222,25 +270,43 @@ const char *vlc_readdir (DIR *dir)
         p_dir->u.drives &= ~(1UL << i);
         assert (i < 26);
 
-        if (asprintf (&p_dir->entry, "%c:\\", 'A' + i) == -1)
-            p_dir->entry = NULL;
+        p_dir->entry[0] = 'A' + i;
+        return p_dir->entry;
     }
-    else
 #endif
+
+    free(p_dir->entry);
     if (p_dir->u.insert_dot_dot)
     {
         /* Adds "..", gruik! */
         p_dir->u.insert_dot_dot = false;
         p_dir->entry = strdup ("..");
     }
+    else if (p_dir->eol)
+        p_dir->entry = NULL;
     else
     {
-        struct _wdirent *ent = _wreaddir (p_dir->wdir);
-        p_dir->entry = (ent != NULL) ? FromWide (ent->d_name) : NULL;
+        p_dir->entry = FromWide(p_dir->wdir.cFileName);
+        p_dir->eol = !FindNextFileW(p_dir->fHandle, &p_dir->wdir);
     }
     return p_dir->entry;
 }
 
+void vlc_rewinddir( vlc_DIR *wdir )
+{
+    if (wdir->fHandle == INVALID_HANDLE_VALUE)
+    {
+        FindClose(wdir->fHandle);
+        wdir->fHandle = FindFirstFileExW(wdir->wildcard, FindExInfoBasic,
+                                         &wdir->wdir, (FINDEX_SEARCH_OPS)0,
+                                         NULL, FIND_FIRST_EX_LARGE_FETCH);
+    }
+    else
+    {
+        wdir->u.drives = GetLogicalDrives();
+    }
+}
+
 int vlc_stat (const char *filename, struct stat *buf)
 {
     wchar_t *wpath = widen_path (filename);



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/61418e68bbb054cec491ed852f9b654b58c9563b...2d8beeb2fe4f33d42227aa8ee0ed0c475651c9cb

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/61418e68bbb054cec491ed852f9b654b58c9563b...2d8beeb2fe4f33d42227aa8ee0ed0c475651c9cb
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