import zend standard tests
[hiphop-php.git] / hphp / test / zend / good / ext-standard-file / fseek_variation3.php
blob467e552ed39e3c87edf6cbf577c5b02306665b44
1 <?php
2 /* Prototype : proto int fseek(resource fp, int offset [, int whence])
3 * Description: Seek on a file pointer
4 * Source code: ext/standard/file.c
5 * Alias to functions: gzseek
6 */
8 echo "*** Testing fseek() : variation - beyond file boundaries ***\n";
10 $outputfile = __FILE__.".tmp";
12 $h = fopen($outputfile, "wb+");
13 for ($i = 1; $i < 10; $i++) {
14 fwrite($h, chr(0x30 + $i));
17 echo "--- fseek beyond start of file ---\n";
18 var_dump(fseek($h, -4, SEEK_SET));
19 echo "after -4 seek: ".bin2hex(fread($h,1))."\n";
20 var_dump(fseek($h, -1, SEEK_CUR));
21 echo "after seek back 1: ".bin2hex(fread($h,1))."\n";
22 var_dump(fseek($h, -20, SEEK_CUR));
23 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";
32 fclose($h);
33 unlink($outputfile);
35 echo "Done";