Advertisement
Guest User

Untitled

a guest
May 21st, 2011
376
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.67 KB | None | 0 0
  1. // emulate large fseek($fp, $pos, SEEK_SET) on 32-bit system
  2. // requires bcmath
  3. function emulated_fseek($fp, $pos) {
  4.     if(bccomp((string)PHP_INT_MAX, $pos, 0) > -1) // small, do it natively
  5.         fseek($fp, (int)$pos, SEEK_SET);
  6.     else {
  7.         fseek($fp, PHP_INT_MAX, SEEK_SET);
  8.         fread($fp, 1); // get past fseek limitation
  9.         $pos = bcsub(bcsub($pos, (string)PHP_INT_MAX), 1);
  10.        
  11.         $chunk = 8192-1; // get around weird 8KB limitation
  12.         while($pos) {
  13.             if(bccomp((string)$chunk, $pos, 0) > -1) {
  14.                 fseek($fp, (int)$pos, SEEK_CUR);
  15.                 break;
  16.             }
  17.             else {
  18.                 fseek($fp, $chunk, SEEK_CUR);
  19.                 fread($fp, 1);
  20.                 $pos = bcsub($pos, (string)($chunk+1));
  21.             }
  22.         }
  23.     }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement