Commit | Line | Data |
ea2b5ef6 |
1 | # NOTE: this file tests how large files (>2GB) work with raw system IO. |
2 | # open(), tell(), seek(), print(), read() are tested in t/op/lfs.t. |
3 | # If you modify/add tests here, remember to update also t/op/lfs.t. |
4 | |
5 | BEGIN { |
6 | eval { my $q = pack "q", 0 }; |
7 | if ($@) { |
8 | print "1..0\n# no 64-bit types\n"; |
9 | bye(); |
10 | } |
11 | chdir 't' if -d 't'; |
12 | unshift @INC, '../lib'; |
13 | require Fcntl; import Fcntl; |
14 | } |
15 | |
16 | sub bye { |
17 | close(BIG); |
18 | unlink "big"; |
19 | exit(0); |
20 | } |
21 | |
22 | # First try to figure out whether we have sparse files. |
23 | |
24 | if ($^O eq 'win32' || $^O eq 'vms') { |
25 | print "1..0\n# no sparse files\n"; |
26 | bye(); |
27 | } |
28 | |
29 | # We'll start off by creating a one megabyte file which has |
30 | # only three "true" bytes. |
31 | |
32 | sysopen(BIG, "big", O_WRONLY|O_CREAT|O_TRUNC) or |
33 | do { warn "sysopen failed: $!\n"; bye }; |
34 | sysseek(BIG, 1_000_000, SEEK_SET); |
35 | syswrite(BIG, "big"); |
36 | close(BIG); |
37 | |
38 | my @s; |
39 | |
40 | @s = stat("big"); |
41 | |
42 | print "# @s\n"; |
43 | |
44 | unless (@s == 13 && |
45 | $s[7] == 1_000_003 && |
46 | defined $s[11] && |
47 | defined $s[12] && |
48 | $s[11] * $s[12] < 1000_003) { |
49 | print "1..0\n# no sparse files?\n"; |
50 | bye(); |
51 | } |
52 | |
53 | # By now we better be sure that we do have sparse files: |
54 | # if we are not, the following will hog 5 gigabytes of disk. Ooops. |
55 | |
56 | print "1..8\n"; |
57 | |
58 | sysopen(BIG, "big", O_WRONLY|O_CREAT|O_TRUNC) or |
59 | do { warn "sysopen failed: $!\n"; bye }; |
60 | sysseek(BIG, 5_000_000_000, SEEK_SET); |
61 | syswrite(BIG, "big"); |
62 | close BIG; |
63 | |
64 | @s = stat("big"); |
65 | |
66 | print "# @s\n"; |
67 | |
68 | print "not " unless $s[7] == 5_000_000_003; |
69 | print "ok 1\n"; |
70 | |
71 | print "not " unless -s "big" == 5_000_000_003; |
72 | print "ok 2\n"; |
73 | |
74 | sysopen(BIG, "big", O_RDONLY) or do { warn "sysopen failed: $!\n"; bye }; |
75 | |
76 | sysseek(BIG, 4_500_000_000, SEEK_SET); |
77 | |
78 | print "not " unless sysseek(BIG, 0, SEEK_CUR) == 4_500_000_000; |
79 | print "ok 3\n"; |
80 | |
81 | sysseek(BIG, 1, SEEK_CUR); |
82 | |
83 | print "not " unless sysseek(BIG, 0, SEEK_CUR) == 4_500_000_001; |
84 | print "ok 4\n"; |
85 | |
86 | sysseek(BIG, -1, SEEK_CUR); |
87 | |
88 | print "not " unless sysseek(BIG, 0, SEEK_CUR) == 4_500_000_000; |
89 | print "ok 5\n"; |
90 | |
91 | sysseek(BIG, -3, SEEK_END); |
92 | |
93 | print "not " unless sysseek(BIG, 0, SEEK_CUR) == 5_000_000_000; |
94 | print "ok 6\n"; |
95 | |
96 | my $big; |
97 | |
98 | print "not " unless sysread(BIG, $big, 3) == 3; |
99 | print "ok 7\n"; |
100 | |
101 | print "not " unless $big eq "big"; |
102 | print "ok 8\n"; |
103 | |
104 | bye(); |
105 | |
106 | # eof |