This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Unapply an experimental patch that accidentally escaped
[perl5.git] / t / lib / syslfs.t
CommitLineData
ea2b5ef6
JH
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
5BEGIN {
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
16sub bye {
17 close(BIG);
18 unlink "big";
19 exit(0);
20}
21
22# First try to figure out whether we have sparse files.
23
24if ($^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
32sysopen(BIG, "big", O_WRONLY|O_CREAT|O_TRUNC) or
33 do { warn "sysopen failed: $!\n"; bye };
34sysseek(BIG, 1_000_000, SEEK_SET);
35syswrite(BIG, "big");
36close(BIG);
37
38my @s;
39
40@s = stat("big");
41
42print "# @s\n";
43
44unless (@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
56print "1..8\n";
57
58sysopen(BIG, "big", O_WRONLY|O_CREAT|O_TRUNC) or
59 do { warn "sysopen failed: $!\n"; bye };
60sysseek(BIG, 5_000_000_000, SEEK_SET);
61syswrite(BIG, "big");
62close BIG;
63
64@s = stat("big");
65
66print "# @s\n";
67
68print "not " unless $s[7] == 5_000_000_003;
69print "ok 1\n";
70
71print "not " unless -s "big" == 5_000_000_003;
72print "ok 2\n";
73
74sysopen(BIG, "big", O_RDONLY) or do { warn "sysopen failed: $!\n"; bye };
75
76sysseek(BIG, 4_500_000_000, SEEK_SET);
77
78print "not " unless sysseek(BIG, 0, SEEK_CUR) == 4_500_000_000;
79print "ok 3\n";
80
81sysseek(BIG, 1, SEEK_CUR);
82
83print "not " unless sysseek(BIG, 0, SEEK_CUR) == 4_500_000_001;
84print "ok 4\n";
85
86sysseek(BIG, -1, SEEK_CUR);
87
88print "not " unless sysseek(BIG, 0, SEEK_CUR) == 4_500_000_000;
89print "ok 5\n";
90
91sysseek(BIG, -3, SEEK_END);
92
93print "not " unless sysseek(BIG, 0, SEEK_CUR) == 5_000_000_000;
94print "ok 6\n";
95
96my $big;
97
98print "not " unless sysread(BIG, $big, 3) == 3;
99print "ok 7\n";
100
101print "not " unless $big eq "big";
102print "ok 8\n";
103
104bye();
105
106# eof