shithub: libdvdcss

Download patch

ref: 7de33d1293d14c57579f162670586292d90995fa
parent: 90a9da373db4ac33cf45acf1db92f427a3111e7d
author: Diego Biurrun <[email protected]>
date: Wed Nov 12 18:42:15 EST 2014

Eliminate unnecessary i_read_fd / i_raw_fd indirections.

There is no need to employ separate file descriptors.

--- a/src/device.c
+++ b/src/device.c
@@ -392,9 +392,9 @@
 #ifdef DVDCSS_RAW_OPEN
 int dvdcss_raw_open ( dvdcss_t dvdcss, const char *psz_device )
 {
-    dvdcss->i_raw_fd = open( psz_device, 0 );
+    int i_fd = open( psz_device, 0 );
 
-    if( dvdcss->i_raw_fd == -1 )
+    if( i_fd == -1 )
     {
         print_debug( dvdcss, "cannot open %s (%s)",
                              psz_device, strerror(errno) );
@@ -403,7 +403,7 @@
     }
     else
     {
-        dvdcss->i_read_fd = dvdcss->i_raw_fd;
+        dvdcss->i_fd = i_fd;
     }
 
     return 0;
@@ -431,14 +431,6 @@
 #else
     close( dvdcss->i_fd );
 
-#ifdef DVDCSS_RAW_OPEN
-    if( dvdcss->i_raw_fd >= 0 )
-    {
-        close( dvdcss->i_raw_fd );
-        dvdcss->i_raw_fd = -1;
-    }
-#endif
-
     return 0;
 #endif
 }
@@ -450,7 +442,7 @@
  *****************************************************************************/
 static int libc_open ( dvdcss_t dvdcss, const char *psz_device )
 {
-    dvdcss->i_fd = dvdcss->i_read_fd = open( psz_device, O_BINARY );
+    dvdcss->i_fd = open( psz_device, O_BINARY );
 
     if( dvdcss->i_fd == -1 )
     {
@@ -526,7 +518,7 @@
 
     setmode( hfile, O_BINARY );
 
-    dvdcss->i_fd = dvdcss->i_read_fd = hfile;
+    dvdcss->i_fd = hfile;
 
     dvdcss->i_pos = 0;
 
@@ -548,7 +540,7 @@
     }
 
     i_seek = (off_t)i_blocks * (off_t)DVDCSS_BLOCK_SIZE;
-    i_seek = lseek( dvdcss->i_read_fd, i_seek, SEEK_SET );
+    i_seek = lseek( dvdcss->i_fd, i_seek, SEEK_SET );
 
     if( i_seek < 0 )
     {
@@ -599,7 +591,7 @@
     off_t i_size, i_ret, i_ret_blocks;
 
     i_size = (off_t)i_blocks * (off_t)DVDCSS_BLOCK_SIZE;
-    i_ret = read( dvdcss->i_read_fd, p_buffer, i_size );
+    i_ret = read( dvdcss->i_fd, p_buffer, i_size );
 
     if( i_ret < 0 )
     {
@@ -708,7 +700,7 @@
     dvdcss->i_pos += i_total;
     return i_total;
 #else
-    int i_read = readv( dvdcss->i_read_fd, p_iovec, i_blocks );
+    int i_read = readv( dvdcss->i_fd, p_iovec, i_blocks );
 
     if( i_read < 0 )
     {
--- a/src/libdvdcss.c
+++ b/src/libdvdcss.c
@@ -473,9 +473,6 @@
     }
 
     /* Initialize structure with default values. */
-#ifdef DVDCSS_RAW_OPEN
-    dvdcss->i_raw_fd = -1;
-#endif
     dvdcss->p_titles = NULL;
     dvdcss->psz_device = strdup( psz_target );
     dvdcss->psz_error = "no error";
--- a/src/libdvdcss.h
+++ b/src/libdvdcss.h
@@ -50,7 +50,6 @@
     /* File descriptor */
     char * psz_device;
     int    i_fd;
-    int    i_read_fd;
     int    i_pos;
 
     /* File handling */
@@ -79,10 +78,6 @@
     char * p_readv_buffer;
     int    i_readv_buf_size;
 #endif /* WIN32 */
-
-#ifdef DVDCSS_RAW_OPEN
-    int    i_raw_fd;
-#endif
 };
 
 /*****************************************************************************