[libdvdnav-devel] [PATCH 2/2] findDirFile: try exact match first

Floris Bos bos at je-eigen-domein.nl
Thu Dec 15 20:02:22 CET 2016


Previously findDirFile() always searched the entire directory
listing to perform a case insensitive search on a file name.

Change this to check for the existence of a file with the
exact name specified first.
Solves a corner case involving virtual file system implementations
that have not implemented directory listings.

Signed-off-by: Floris Bos <bos at je-eigen-domein.nl>
---
 src/dvd_reader.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/src/dvd_reader.c b/src/dvd_reader.c
index a9034de..e8371c6 100644
--- a/src/dvd_reader.c
+++ b/src/dvd_reader.c
@@ -667,6 +667,14 @@ static int findDirFile( const char *path, const char *file, char *filename )
 {
   DIR *dir;
   struct dirent *ent;
+  struct stat st;
+
+  /* Try exact match first, before resorting to listing entire directory */
+  sprintf( filename, "%s%s%s", path,
+           ( ( path[ strlen( path ) - 1 ] == '/' ) ? "" : "/" ),
+           file );
+  if ( stat(filename, &st) == 0 )
+    return 0;
 
   dir = opendir( path );
   if( !dir ) return -2;
-- 
2.7.4



More information about the libdvdnav-devel mailing list