summaryrefslogtreecommitdiffstats
path: root/libmpdvdkit2/device.c
diff options
context:
space:
mode:
Diffstat (limited to 'libmpdvdkit2/device.c')
-rw-r--r--libmpdvdkit2/device.c63
1 files changed, 31 insertions, 32 deletions
diff --git a/libmpdvdkit2/device.c b/libmpdvdkit2/device.c
index 7b50e912f8..89d73ad358 100644
--- a/libmpdvdkit2/device.c
+++ b/libmpdvdkit2/device.c
@@ -2,9 +2,6 @@
* device.h: DVD device access
*****************************************************************************
* Copyright (C) 1998-2002 VideoLAN
- *
- * Modified for use with MPlayer, changes contained in libdvdcss_changes.diff.
- * detailed CVS changelog at http://www.mplayerhq.hu/cgi-bin/cvsweb.cgi/main/
* $Id$
*
* Authors: Stéphane Borel <stef@via.ecp.fr>
@@ -34,11 +31,12 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+# include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
-#include <unistd.h>
-#include <limits.h>
+# include <unistd.h>
+# include <limits.h>
#if defined( WIN32 ) && !defined( SYS_CYGWIN )
# include <io.h> /* read() */
@@ -129,12 +127,9 @@ int _dvdcss_use_ioctls( dvdcss_t dvdcss )
int _dvdcss_open ( dvdcss_t dvdcss )
{
- char psz_debug[200];
char const *psz_device = dvdcss->psz_device;
- snprintf( psz_debug, 199, "opening target `%s'", psz_device );
- psz_debug[199] = '\0';
- _dvdcss_debug( dvdcss, psz_debug );
+ print_debug( dvdcss, "opening target `%s'", psz_device );
#if defined( WIN32 )
dvdcss->b_file = 1;
@@ -149,7 +144,7 @@ int _dvdcss_open ( dvdcss_t dvdcss )
if( !dvdcss->b_file && WIN2K )
{
- _dvdcss_debug( dvdcss, "using Win2K API for access" );
+ print_debug( dvdcss, "using Win2K API for access" );
dvdcss->pf_seek = win2k_seek;
dvdcss->pf_read = win2k_read;
dvdcss->pf_readv = win_readv;
@@ -157,7 +152,7 @@ int _dvdcss_open ( dvdcss_t dvdcss )
}
else if( !dvdcss->b_file )
{
- _dvdcss_debug( dvdcss, "using ASPI for access" );
+ print_debug( dvdcss, "using ASPI for access" );
dvdcss->pf_seek = aspi_seek;
dvdcss->pf_read = aspi_read;
dvdcss->pf_readv = win_readv;
@@ -166,7 +161,7 @@ int _dvdcss_open ( dvdcss_t dvdcss )
else
#endif
{
- _dvdcss_debug( dvdcss, "using libc for access" );
+ print_debug( dvdcss, "using libc for access" );
dvdcss->pf_seek = libc_seek;
dvdcss->pf_read = libc_read;
dvdcss->pf_readv = libc_readv;
@@ -181,7 +176,9 @@ int _dvdcss_raw_open ( dvdcss_t dvdcss, char const *psz_device )
if( dvdcss->i_raw_fd == -1 )
{
- _dvdcss_error( dvdcss, "failed opening raw device, continuing" );
+ print_debug( dvdcss, "cannot open %s (%s)",
+ psz_device, strerror(errno) );
+ print_error( dvdcss, "failed to open raw device, but continuing" );
return -1;
}
else
@@ -250,7 +247,9 @@ static int libc_open ( dvdcss_t dvdcss, char const *psz_device )
if( dvdcss->i_fd == -1 )
{
- _dvdcss_error( dvdcss, "failed opening device" );
+ print_debug( dvdcss, "cannot open %s (%s)",
+ psz_device, strerror(errno) );
+ print_error( dvdcss, "failed to open device" );
return -1;
}
@@ -287,7 +286,7 @@ static int win2k_open ( dvdcss_t dvdcss, char const *psz_device )
if( (HANDLE) dvdcss->i_fd == INVALID_HANDLE_VALUE )
{
- _dvdcss_error( dvdcss, "failed opening device" );
+ print_error( dvdcss, "failed opening device" );
return -1;
}
@@ -310,7 +309,7 @@ static int aspi_open( dvdcss_t dvdcss, char const * psz_device )
hASPI = LoadLibrary( "wnaspi32.dll" );
if( hASPI == NULL )
{
- _dvdcss_error( dvdcss, "unable to load wnaspi32.dll" );
+ print_error( dvdcss, "unable to load wnaspi32.dll" );
return -1;
}
@@ -319,7 +318,7 @@ static int aspi_open( dvdcss_t dvdcss, char const * psz_device )
if(lpGetSupport == NULL || lpSendCommand == NULL )
{
- _dvdcss_error( dvdcss, "unable to get aspi function pointers" );
+ print_error( dvdcss, "unable to get aspi function pointers" );
FreeLibrary( hASPI );
return -1;
}
@@ -328,14 +327,14 @@ static int aspi_open( dvdcss_t dvdcss, char const * psz_device )
if( HIBYTE( LOWORD ( dwSupportInfo ) ) == SS_NO_ADAPTERS )
{
- _dvdcss_error( dvdcss, "no ASPI adapters found" );
+ print_error( dvdcss, "no ASPI adapters found" );
FreeLibrary( hASPI );
return -1;
}
if( HIBYTE( LOWORD ( dwSupportInfo ) ) != SS_COMP )
{
- _dvdcss_error( dvdcss, "unable to initalize aspi layer" );
+ print_error( dvdcss, "unable to initalize aspi layer" );
FreeLibrary( hASPI );
return -1;
}
@@ -343,7 +342,7 @@ static int aspi_open( dvdcss_t dvdcss, char const * psz_device )
i_hostadapters = LOBYTE( LOWORD( dwSupportInfo ) );
if( i_hostadapters == 0 )
{
- _dvdcss_error( dvdcss, "no ASPI adapters ready" );
+ print_error( dvdcss, "no ASPI adapters ready" );
FreeLibrary( hASPI );
return -1;
}
@@ -351,7 +350,7 @@ static int aspi_open( dvdcss_t dvdcss, char const * psz_device )
fd = malloc( sizeof( struct w32_aspidev ) );
if( fd == NULL )
{
- _dvdcss_error( dvdcss, "not enough memory" );
+ print_error( dvdcss, "not enough memory" );
FreeLibrary( hASPI );
return -1;
}
@@ -402,7 +401,7 @@ static int aspi_open( dvdcss_t dvdcss, char const * psz_device )
{
free( (void*) fd );
FreeLibrary( hASPI );
- _dvdcss_error( dvdcss,"this is not a cdrom drive" );
+ print_error( dvdcss,"this is not a cdrom drive" );
return -1;
}
}
@@ -411,7 +410,7 @@ static int aspi_open( dvdcss_t dvdcss, char const * psz_device )
free( (void*) fd );
FreeLibrary( hASPI );
- _dvdcss_error( dvdcss, "unable to get haid and target (aspi)" );
+ print_error( dvdcss, "unable to get haid and target (aspi)" );
return -1;
}
#endif
@@ -429,12 +428,12 @@ static int libc_seek( dvdcss_t dvdcss, int i_blocks )
return i_blocks;
}
- i_seek = lseek( dvdcss->i_read_fd,
- (off_t)i_blocks * (off_t)DVDCSS_BLOCK_SIZE, SEEK_SET );
+ i_seek = (off_t)i_blocks * (off_t)DVDCSS_BLOCK_SIZE;
+ i_seek = lseek( dvdcss->i_read_fd, i_seek, SEEK_SET );
if( i_seek < 0 )
{
- _dvdcss_error( dvdcss, "seek error" );
+ print_error( dvdcss, "seek error" );
dvdcss->i_pos = -1;
return i_seek;
}
@@ -511,20 +510,20 @@ static int aspi_seek( dvdcss_t dvdcss, int i_blocks )
*****************************************************************************/
static int libc_read ( dvdcss_t dvdcss, void *p_buffer, int i_blocks )
{
- off_t i_ret;
+ off_t i_size, i_ret;
- i_ret = read( dvdcss->i_read_fd, p_buffer,
- (off_t)i_blocks * DVDCSS_BLOCK_SIZE );
+ i_size = (off_t)i_blocks * (off_t)DVDCSS_BLOCK_SIZE;
+ i_ret = read( dvdcss->i_read_fd, p_buffer, i_size );
if( i_ret < 0 )
{
- _dvdcss_error( dvdcss, "read error" );
+ print_error( dvdcss, "read error" );
dvdcss->i_pos = -1;
return i_ret;
}
/* Handle partial reads */
- if( i_ret != (off_t)i_blocks * DVDCSS_BLOCK_SIZE )
+ if( i_ret != i_size )
{
int i_seek;
@@ -667,7 +666,7 @@ static int win_readv ( dvdcss_t dvdcss, struct iovec *p_iovec, int i_blocks )
dvdcss->p_readv_buffer = malloc( dvdcss->i_readv_buf_size );
if( !dvdcss->p_readv_buffer )
{
- _dvdcss_error( dvdcss, " failed (readv)" );
+ print_error( dvdcss, " failed (readv)" );
dvdcss->i_pos = -1;
return -1;
}