fseek_variation3.phpt 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. --TEST--
  2. Test fseek() function : variation functionality beyond file boundaries
  3. --CREDITS--
  4. Dave Kelsey <d_kelsey@uk.ibm.com>
  5. --FILE--
  6. <?php
  7. echo "*** Testing fseek() : variation - beyond file boundaries ***\n";
  8. $outputfile = __FILE__.".tmp";
  9. $h = fopen($outputfile, "wb+");
  10. for ($i = 1; $i < 10; $i++) {
  11. fwrite($h, chr(0x30 + $i));
  12. }
  13. echo "--- fseek beyond start of file ---\n";
  14. var_dump(fseek($h, -4, SEEK_SET));
  15. echo "after -4 seek: ".bin2hex(fread($h,1))."\n";
  16. var_dump(fseek($h, -1, SEEK_CUR));
  17. echo "after seek back 1: ".bin2hex(fread($h,1))."\n";
  18. var_dump(fseek($h, -20, SEEK_CUR));
  19. echo "after seek back 20: ".bin2hex(fread($h,1))."\n";
  20. echo "--- fseek beyond end of file ---\n";
  21. var_dump(fseek($h, 16, SEEK_SET));
  22. fwrite($h, "end");
  23. fseek($h ,0, SEEK_SET);
  24. $data = fread($h, 4096);
  25. echo bin2hex($data)."\n";
  26. fclose($h);
  27. unlink($outputfile);
  28. echo "Done";
  29. ?>
  30. --EXPECT--
  31. *** Testing fseek() : variation - beyond file boundaries ***
  32. --- fseek beyond start of file ---
  33. int(-1)
  34. after -4 seek:
  35. int(0)
  36. after seek back 1: 39
  37. int(-1)
  38. after seek back 20:
  39. --- fseek beyond end of file ---
  40. int(0)
  41. 31323334353637383900000000000000656e64
  42. Done