[vlc-commits] dvdnav: cleanup probing

Rémi Denis-Courmont git at videolan.org
Sat May 7 10:53:58 CEST 2011


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sat May  7 11:47:28 2011 +0300| [59d12a2083bc0be1aaa348a8e0d7014dbd4dfc37] | committer: Rémi Denis-Courmont

dvdnav: cleanup probing

- Do not probe paths that do not exist (ENOENT).
- If the OS supports open()ing directories (HAVE_FDOPENDIR), do not
  probe paths that cannot be opened.
- Do not probe files whereby fstat() fails.
- Do not probe non-regular files other than directories and block
  devices (previously, only FIFOs were discarded).
- Look for anchor even if fstat() is not supported.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=59d12a2083bc0be1aaa348a8e0d7014dbd4dfc37
---

 modules/access/dvdnav.c |   53 +++++++++++++++++++++++------------------------
 1 files changed, 26 insertions(+), 27 deletions(-)

diff --git a/modules/access/dvdnav.c b/modules/access/dvdnav.c
index 857d734..c85378b 100644
--- a/modules/access/dvdnav.c
+++ b/modules/access/dvdnav.c
@@ -1448,43 +1448,42 @@ static int EventIntf( vlc_object_t *p_input, char const *psz_var,
  *****************************************************************************/
 static int ProbeDVD( const char *psz_name )
 {
-#ifdef HAVE_SYS_STAT_H
-    struct stat stat_info;
-    uint8_t pi_anchor[2];
-    int i_fd, i_ret;
-
     if( !*psz_name )
-    {
         /* Triggers libdvdcss autodetection */
         return VLC_SUCCESS;
-    }
 
-    if( (i_fd = vlc_open( psz_name, O_RDONLY |O_NONBLOCK )) == -1 )
-    {
-        return VLC_SUCCESS; /* Let dvdnav_open() do the probing */
-    }
+    int fd = vlc_open( psz_name, O_RDONLY | O_NONBLOCK );
+    if( fd == -1 )
+#ifdef HAVE_FDOPENDIR
+        return VLC_EGENERIC;
+#else
+        return (errno == ENOENT) ? VLC_EGENERIC : VLC_SUCCESS;
+#endif
+
+    int ret = VLC_EGENERIC;
 
-    i_ret = VLC_EGENERIC;
+#ifdef HAVE_SYS_STAT_H
+    struct stat stat_info;
+
+    if( fstat( fd, &stat_info ) == -1 )
+         goto bailout;
 
-    if( fstat( i_fd, &stat_info ) || !S_ISREG( stat_info.st_mode ) )
+    if( !S_ISREG( stat_info.st_mode ) )
     {
-        if( !S_ISFIFO( stat_info.st_mode ) )
-            i_ret = VLC_SUCCESS; /* Let dvdnav_open() do the probing */
+        if( S_ISDIR( stat_info.st_mode ) || S_ISBLK( stat_info.st_mode ) )
+            ret = VLC_SUCCESS; /* Let dvdnav_open() do the probing */
         goto bailout;
     }
-
+#endif
     /* Try to find the anchor (2 bytes at LBA 256) */
-    if( lseek( i_fd, 256 * DVD_VIDEO_LB_LEN, SEEK_SET ) != -1
-     && read( i_fd, pi_anchor, 2 ) == 2
-     && GetWLE( pi_anchor ) == 2 )
-        i_ret = VLC_SUCCESS; /* Found a potential anchor */
+    uint16_t anchor;
 
-bailout:
-    close( i_fd );
+    if( lseek( fd, 256 * DVD_VIDEO_LB_LEN, SEEK_SET ) != -1
+     && read( fd, &anchor, 2 ) == 2
+     && GetWLE( &anchor ) == 2 )
+        ret = VLC_SUCCESS; /* Found a potential anchor */
 
-    return i_ret;
-#else
-
-    return VLC_SUCCESS;
-#endif
+bailout:
+    close( fd );
+    return ret;
 }



More information about the vlc-commits mailing list