1 #!/usr/local/bin/perl -ws
7 use Fcntl qw( :seek ) ;
10 use File::ReadBackwards ;
12 # NOTE: much of this code was taken from the core perl test script
13 # ops/lfs.t. it was modified to test File::ReadBackwards and large files
15 my %has_no_sparse_files = map { $_ => 1 }
16 qw( MSWin32 NetWare VMS unicos ) ;
18 my $test_file = 'bw.data' ;
21 "3rd from last line\n",
26 my $test_text = join '', @test_lines ;
31 my( $skip_text ) = @_ ;
34 plan skip_all => $skip_text ;
37 if( $Config{lseeksize} < 8 ) {
38 skip_all_tests( "no 64-bit file offsets\n" ) ;
41 unless( $Config{uselargefiles} ) {
42 skip_all_tests( "no large file support\n" ) ;
45 if ( $has_no_sparse_files{ $^O } ) {
46 skip_all_tests( "no sparse files in $^O\n" ) ;
49 # run the long seek code below in a subprocess in case it exits with a
52 my $rc = system $^X, '-e', <<"EOF";
53 open(BIG, ">$test_file");
54 seek(BIG, 5_000_000_000, 0);
55 print BIG "$test_text" ;
61 my $error = 'signal ' . ($rc & 0x7f) ;
62 skip_all_tests( "seeking past 2GB failed: $error" ) ;
65 open(BIG, ">$test_file");
67 unless( seek(BIG, 5_000_000_000, 0) ) {
68 skip_all_tests( "seeking past 2GB failed: $!" ) ;
72 # Either the print or (more likely, thanks to buffering) the close will
73 # fail if there are are filesize limitations (process or fs).
75 my $print = print BIG $test_text ;
76 my $close = close BIG;
78 unless ($print && $close) {
80 print "# print failed: $!\n" unless $print;
81 print "# close failed: $!\n" unless $close;
83 if( $! =~/too large/i ) {
84 skip_all_tests( 'writing past 2GB failed: process limits?' ) ;
87 if( $! =~ /quota/i ) {
88 skip_all_tests( 'filesystem quota limits?' ) ;
91 skip_all_tests( "large file error: $!" ) ;
96 my $bw = File::ReadBackwards->new( $test_file ) or
97 die "can't open $test_file: $!" ;
99 my $line = $bw->readline() ;
100 is( $line, $test_lines[-1], 'last line' ) ;
102 $line = $bw->readline() ;
103 is( $line, $test_lines[-2], 'next to last line' ) ;