Long double patches from Dan Sugalski.
[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 {
05f8a9f5 6 # Don't bother if there are no quads.
ea2b5ef6 7 eval { my $q = pack "q", 0 };
817e2dcb 8 if ($@) {
9 print "1..0\n# no 64-bit types\n";
ea2b5ef6 10 bye();
817e2dcb 11 }
ea2b5ef6 12 chdir 't' if -d 't';
13 unshift @INC, '../lib';
817e2dcb 14}
15
6da84e39 16sub bye {
17 close(BIG);
18 unlink "big";
19 exit(0);
20}
21
05f8a9f5 22# Known have-nots.
817e2dcb 23if ($^O eq 'win32' || $^O eq 'vms') {
24 print "1..0\n# no sparse files\n";
6da84e39 25 bye();
26}
27
05f8a9f5 28# Then try to deduce whether we have sparse files.
29
ea2b5ef6 30my ($SEEK_SET, $SEEK_CUR, $SEEK_END) = (0, 1, 2);
6da84e39 31
ea2b5ef6 32# We'll start off by creating a one megabyte file which has
05f8a9f5 33# only three "true" bytes. If we have sparseness, we should
34# consume less blocks than one megabyte (assuming nobody has
35# one megabyte blocks...)
817e2dcb 36
ea2b5ef6 37open(BIG, ">big") or do { warn "open failed: $!\n"; bye };
6da84e39 38binmode BIG;
ea2b5ef6 39seek(BIG, 1_000_000, $SEEK_SET);
6da84e39 40print BIG "big";
817e2dcb 41close(BIG);
42
43my @s;
44
45@s = stat("big");
46
ea2b5ef6 47print "# @s\n";
48
6da84e39 49unless (@s == 13 &&
ea2b5ef6 50 $s[7] == 1_000_003 &&
6da84e39 51 defined $s[11] &&
52 defined $s[12] &&
ea2b5ef6 53 $s[11] * $s[12] < 1000_003) {
54 print "1..0\n# no sparse files?\n";
6da84e39 55 bye();
817e2dcb 56}
57
58# By now we better be sure that we do have sparse files:
59# if we are not, the following will hog 5 gigabytes of disk. Ooops.
60
61print "1..8\n";
62
05f8a9f5 63my $fail = 0;
64
ea2b5ef6 65open(BIG, ">big") or do { warn "open failed: $!\n"; bye };
817e2dcb 66binmode BIG;
6da84e39 67seek(BIG, 5_000_000_000, $SEEK_SET);
817e2dcb 68print BIG "big";
69close BIG;
70
71@s = stat("big");
72
ea2b5ef6 73print "# @s\n";
74
05f8a9f5 75sub fail () {
76 print " not ";
77 $fail++;
78}
79
80fail unless $s[7] == 5_000_000_003;
817e2dcb 81print "ok 1\n";
82
05f8a9f5 83fail unless -s "big" == 5_000_000_003;
817e2dcb 84print "ok 2\n";
85
ea2b5ef6 86open(BIG, "big") or do { warn "open failed: $!\n"; bye };
817e2dcb 87binmode BIG;
88
6da84e39 89seek(BIG, 4_500_000_000, $SEEK_SET);
817e2dcb 90
05f8a9f5 91fail unless tell(BIG) == 4_500_000_000;
817e2dcb 92print "ok 3\n";
93
6da84e39 94seek(BIG, 1, $SEEK_CUR);
817e2dcb 95
05f8a9f5 96fail unless tell(BIG) == 4_500_000_001;
817e2dcb 97print "ok 4\n";
98
6da84e39 99seek(BIG, -1, $SEEK_CUR);
817e2dcb 100
05f8a9f5 101fail unless tell(BIG) == 4_500_000_000;
817e2dcb 102print "ok 5\n";
103
6da84e39 104seek(BIG, -3, $SEEK_END);
817e2dcb 105
05f8a9f5 106fail unless tell(BIG) == 5_000_000_000;
817e2dcb 107print "ok 6\n";
108
109my $big;
110
05f8a9f5 111fail unless read(BIG, $big, 3) == 3;
817e2dcb 112print "ok 7\n";
113
05f8a9f5 114fail unless $big eq "big";
817e2dcb 115print "ok 8\n";
116
6da84e39 117bye();
817e2dcb 118
05f8a9f5 119if ($fail) {
120 print STDERR <<EOM;
121#
122# If the lfs (large file support) tests fail, it means that
123# the *file system* you are running the tests on doesn't support
124# large files (files larger than two gigabytes). Perl may still
125# be able to support such files, once you have such a file system.
126#
127EOM
128}
129
6da84e39 130# eof