Commit 59d12a20 authored by Rémi Denis-Courmont's avatar 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.
parent 32b36298
...@@ -1448,43 +1448,42 @@ static int EventIntf( vlc_object_t *p_input, char const *psz_var, ...@@ -1448,43 +1448,42 @@ static int EventIntf( vlc_object_t *p_input, char const *psz_var,
*****************************************************************************/ *****************************************************************************/
static int ProbeDVD( const char *psz_name ) 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 ) if( !*psz_name )
{
/* Triggers libdvdcss autodetection */ /* Triggers libdvdcss autodetection */
return VLC_SUCCESS; return VLC_SUCCESS;
}
if( (i_fd = vlc_open( psz_name, O_RDONLY |O_NONBLOCK )) == -1 ) int fd = vlc_open( psz_name, O_RDONLY | O_NONBLOCK );
{ if( fd == -1 )
return VLC_SUCCESS; /* Let dvdnav_open() do the probing */ #ifdef HAVE_FDOPENDIR
} return VLC_EGENERIC;
#else
return (errno == ENOENT) ? VLC_EGENERIC : VLC_SUCCESS;
#endif
i_ret = VLC_EGENERIC; int ret = VLC_EGENERIC;
if( fstat( i_fd, &stat_info ) || !S_ISREG( stat_info.st_mode ) ) #ifdef HAVE_SYS_STAT_H
struct stat stat_info;
if( fstat( fd, &stat_info ) == -1 )
goto bailout;
if( !S_ISREG( stat_info.st_mode ) )
{ {
if( !S_ISFIFO( stat_info.st_mode ) ) if( S_ISDIR( stat_info.st_mode ) || S_ISBLK( stat_info.st_mode ) )
i_ret = VLC_SUCCESS; /* Let dvdnav_open() do the probing */ ret = VLC_SUCCESS; /* Let dvdnav_open() do the probing */
goto bailout; goto bailout;
} }
#endif
/* Try to find the anchor (2 bytes at LBA 256) */ /* Try to find the anchor (2 bytes at LBA 256) */
if( lseek( i_fd, 256 * DVD_VIDEO_LB_LEN, SEEK_SET ) != -1 uint16_t anchor;
&& read( i_fd, pi_anchor, 2 ) == 2
&& GetWLE( pi_anchor ) == 2 )
i_ret = VLC_SUCCESS; /* Found a potential anchor */
bailout: if( lseek( fd, 256 * DVD_VIDEO_LB_LEN, SEEK_SET ) != -1
close( i_fd ); && read( fd, &anchor, 2 ) == 2
&& GetWLE( &anchor ) == 2 )
ret = VLC_SUCCESS; /* Found a potential anchor */
return i_ret; bailout:
#else close( fd );
return ret;
return VLC_SUCCESS;
#endif
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment