fseek_variation3.phpt 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. /* Prototype : proto int fseek(resource fp, int offset [, int whence])
  8. * Description: Seek on a file pointer
  9. * Source code: ext/standard/file.c
  10. * Alias to functions: gzseek
  11. */
  12. echo "*** Testing fseek() : variation - beyond file boundaries ***\n";
  13. $outputfile = __FILE__.".tmp";
  14. $h = fopen($outputfile, "wb+");
  15. for ($i = 1; $i < 10; $i++) {
  16. fwrite($h, chr(0x30 + $i));
  17. }
  18. echo "--- fseek beyond start of file ---\n";
  19. var_dump(fseek($h, -4, SEEK_SET));
  20. echo "after -4 seek: ".bin2hex(fread($h,1))."\n";
  21. var_dump(fseek($h, -1, SEEK_CUR));
  22. echo "after seek back 1: ".bin2hex(fread($h,1))."\n";
  23. var_dump(fseek($h, -20, SEEK_CUR));
  24. echo "after seek back 20: ".bin2hex(fread($h,1))."\n";
  25. echo "--- fseek beyond end of file ---\n";
  26. var_dump(fseek($h, 16, SEEK_SET));
  27. fwrite($h, b"end");
  28. fseek($h ,0, SEEK_SET);
  29. $data = fread($h, 4096);
  30. echo bin2hex($data)."\n";
  31. fclose($h);
  32. unlink($outputfile);
  33. echo "Done";
  34. ?>
  35. --EXPECTF--
  36. *** Testing fseek() : variation - beyond file boundaries ***
  37. --- fseek beyond start of file ---
  38. int(-1)
  39. after -4 seek:
  40. int(0)
  41. after seek back 1: 39
  42. int(-1)
  43. after seek back 20:
  44. --- fseek beyond end of file ---
  45. int(0)
  46. 31323334353637383900000000000000656e64
  47. Done