shithub: libdvdcss

Download patch

ref: 3a49a3e5a981bf72234f96022fbfe2333fa636fd
parent: 29dd1a4f43b2063d05ed8e8be01102481ea21c0a
author: Diego Biurrun <[email protected]>
date: Fri Oct 24 21:45:02 EDT 2014

device: Refactor a number of block size calculations

--- a/src/device.c
+++ b/src/device.c
@@ -596,7 +596,7 @@
  *****************************************************************************/
 static int libc_read ( dvdcss_t dvdcss, void *p_buffer, int i_blocks )
 {
-    off_t i_size, i_ret;
+    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 );
@@ -608,6 +608,8 @@
         return i_ret;
     }
 
+    i_ret_blocks = i_ret / DVDCSS_BLOCK_SIZE;
+
     /* Handle partial reads */
     if( i_ret != i_size )
     {
@@ -614,7 +616,7 @@
         int i_seek;
 
         dvdcss->i_pos = -1;
-        i_seek = libc_seek( dvdcss, i_ret / DVDCSS_BLOCK_SIZE );
+        i_seek = libc_seek( dvdcss, i_ret_blocks );
         if( i_seek < 0 )
         {
             return i_seek;
@@ -621,11 +623,11 @@
         }
 
         /* We have to return now so that i_pos isn't clobbered */
-        return i_ret / DVDCSS_BLOCK_SIZE;
+        return i_ret_blocks;
     }
 
-    dvdcss->i_pos += i_ret / DVDCSS_BLOCK_SIZE;
-    return i_ret / DVDCSS_BLOCK_SIZE;
+    dvdcss->i_pos += i_ret_blocks;
+    return i_ret_blocks;
 }
 
 #if defined( WIN32 )
@@ -641,8 +643,9 @@
         return -1;
     }
 
-    dvdcss->i_pos += i_bytes / DVDCSS_BLOCK_SIZE;
-    return i_bytes / DVDCSS_BLOCK_SIZE;
+    i_bytes /= DVDCSS_BLOCK_SIZE;
+    dvdcss->i_pos += i_bytes;
+    return i_bytes;
 }
 #endif /* defined( WIN32 ) */
 
@@ -681,6 +684,7 @@
         }
 
         i_total += i_bytes;
+        i_total /= DVDCSS_BLOCK_SIZE;
 
         if( i_bytes != i_len )
         {
@@ -689,7 +693,7 @@
             int i_seek;
 
             dvdcss->i_pos = -1;
-            i_seek = libc_seek( dvdcss, i_total / DVDCSS_BLOCK_SIZE );
+            i_seek = libc_seek( dvdcss, i_total );
             if( i_seek < 0 )
             {
                 return i_seek;
@@ -696,12 +700,12 @@
             }
 
             /* We have to return now so that i_pos isn't clobbered */
-            return i_total / DVDCSS_BLOCK_SIZE;
+            return i_total;
         }
     }
 
-    dvdcss->i_pos += i_total / DVDCSS_BLOCK_SIZE;
-    return i_total / DVDCSS_BLOCK_SIZE;
+    dvdcss->i_pos += i_total;
+    return i_total;
 #else
     int i_read = readv( dvdcss->i_read_fd, p_iovec, i_blocks );
 
@@ -711,8 +715,9 @@
         return i_read;
     }
 
-    dvdcss->i_pos += i_read / DVDCSS_BLOCK_SIZE;
-    return i_read / DVDCSS_BLOCK_SIZE;
+    i_read /= DVDCSS_BLOCK_SIZE;
+    dvdcss->i_pos += i_read;
+    return i_read;
 #endif
 }
 
@@ -752,10 +757,8 @@
 
     if( i_blocks_total <= 0 ) return 0;
 
-    i_blocks_total /= DVDCSS_BLOCK_SIZE;
-
     if( !ReadFile( (HANDLE)dvdcss->i_fd, dvdcss->p_readv_buffer,
-                   i_blocks_total * DVDCSS_BLOCK_SIZE, &i_bytes, NULL ) )
+                   i_blocks_total, &i_bytes, NULL ) )
     {
         /* The read failed... too bad.
          * As in the POSIX spec the file position is left