ftruncate_bug76803.phpt 741 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. --TEST--
  2. Bug #76803 ftruncate changes file pointer
  3. --FILE--
  4. <?php
  5. $fn = __DIR__ . DIRECTORY_SEPARATOR . "test76803";
  6. $f = fopen($fn, "w");
  7. fwrite($f, "Hello");
  8. ftruncate($f, 2);
  9. fwrite($f, "World");
  10. fclose($f);
  11. var_dump(addslashes(file_get_contents($fn)));
  12. $f = fopen($fn, "w");
  13. fwrite($f, "Hello");
  14. ftruncate($f, 2);
  15. fclose($f);
  16. var_dump(addslashes(file_get_contents($fn)));
  17. $f = fopen('php://memory', 'w+');
  18. fwrite($f, 'Hello');
  19. ftruncate($f, 2); // in 7.3 changes file pointer to 2
  20. fwrite($f, 'World');
  21. rewind($f);
  22. var_dump(addslashes(stream_get_contents($f)));
  23. fclose($f);
  24. ?>
  25. --CLEAN--
  26. <?php
  27. $fn = __DIR__ . DIRECTORY_SEPARATOR . "test76803";
  28. unlink($fn);
  29. ?>
  30. --EXPECT--
  31. string(13) "He\0\0\0World"
  32. string(2) "He"
  33. string(7) "HeWorld"