1--TEST--
2Test fseek() function : variation functionality beyond file boundaries
3--CREDITS--
4Dave 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
13echo "*** Testing fseek() : variation - beyond file boundaries ***\n";
14
15$outputfile = __FILE__.".tmp";
16
17$h = fopen($outputfile, "wb+");
18for ($i = 1; $i < 10; $i++) {
19   fwrite($h, chr(0x30 + $i));
20}
21
22echo "--- fseek beyond start of file ---\n";
23var_dump(fseek($h, -4, SEEK_SET));
24echo "after -4 seek: ".bin2hex(fread($h,1))."\n";
25var_dump(fseek($h, -1, SEEK_CUR));
26echo "after seek back 1: ".bin2hex(fread($h,1))."\n";
27var_dump(fseek($h, -20, SEEK_CUR));
28echo "after seek back 20: ".bin2hex(fread($h,1))."\n";
29
30echo "--- fseek beyond end of file ---\n";
31var_dump(fseek($h, 16, SEEK_SET));
32fwrite($h, "end");
33fseek($h ,0, SEEK_SET);
34$data = fread($h, 4096);
35echo bin2hex($data)."\n";
36
37fclose($h);
38unlink($outputfile);
39
40echo "Done";
41?>
42--EXPECTF--
43*** Testing fseek() : variation - beyond file boundaries ***
44--- fseek beyond start of file ---
45int(-1)
46after -4 seek:
47int(0)
48after seek back 1: 39
49int(-1)
50after seek back 20:
51--- fseek beyond end of file ---
52int(0)
5331323334353637383900000000000000656e64
54Done
55