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