X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FFile%2FSlurp.pm;h=f4b91382e2904a1fb0571508fba7d5f891a37d9b;hb=8ed110f93b8011f585c0c4ee23234d11668ac944;hp=6c078bfdfb7a2529ffbe34f30837fdb54436648f;hpb=997098525898485838522aa547a080189cb7a313;p=urisagit%2FPerl-Docs.git diff --git a/lib/File/Slurp.pm b/lib/File/Slurp.pm index 6c078bf..f4b9138 100755 --- a/lib/File/Slurp.pm +++ b/lib/File/Slurp.pm @@ -18,7 +18,7 @@ use vars qw( %EXPORT_TAGS @EXPORT_OK $VERSION @EXPORT ) ; @EXPORT = ( @{ $EXPORT_TAGS{'all'} } ); @EXPORT_OK = qw( slurp ) ; -$VERSION = '9999.13'; +$VERSION = '9999.14'; my $is_win32 = $^O =~ /win32/i ; @@ -29,19 +29,19 @@ my $is_win32 = $^O =~ /win32/i ; # appealing BEGIN block: BEGIN { - unless( eval { defined SEEK_SET() } ) { + unless( defined &SEEK_SET ) { *SEEK_SET = sub { 0 }; *SEEK_CUR = sub { 1 }; *SEEK_END = sub { 2 }; } - unless( eval { defined O_BINARY() } ) { + unless( defined &O_BINARY ) { *O_BINARY = sub { 0 }; *O_RDONLY = sub { 0 }; *O_WRONLY = sub { 1 }; } - unless ( eval { defined O_APPEND() } ) { + unless ( defined O_APPEND ) { if ( $^O =~ /olaris/ ) { *O_APPEND = sub { 8 }; @@ -77,33 +77,25 @@ sub read_file { my( $file_name, %args ) = @_ ; -# my $file_size = -s $file_name ; - - if ( !ref $file_name && -s $file_name < 10000 && ! %args && !wantarray ) { + if ( !ref $file_name && 0 && + -e $file_name && -s _ < 10000 && ! %args && !wantarray ) { local( *FH ) ; -# open( FH, $file_name ) ; - unless( open( FH, $file_name ) ) { @_ = ( \%args, "read_file '$file_name' - sysopen: $!"); goto &_error ; } -#print "OPT\n" and $printed++ unless $printed ; - -# sysread( FH, my $buf, -s _ ) ; -# return $buf ; - -# } my $read_cnt = sysread( FH, my $buf, -s _ ) ; unless ( defined $read_cnt ) { # handle the read error - @_ = ( \%args, "read_file '$file_name' - sysread: $!"); + @_ = ( \%args, + "read_file '$file_name' - small sysread: $!"); goto &_error ; } @@ -178,6 +170,8 @@ ERR $size_left = -s $read_fh ; +print "SIZE $size_left\n" ; + ### TEST # blk_size is not needed if we have a real file size > 0. for 0 size who cares? # so test this deletion @@ -190,22 +184,22 @@ ERR } - if ( $size_left < 10000 && keys %args == 0 && !wantarray ) { +# if ( $size_left < 10000 && keys %args == 0 && !wantarray ) { -#print "OPT\n" and $printed++ unless $printed ; +# #print "OPT\n" and $printed++ unless $printed ; - my $read_cnt = sysread( $read_fh, my $buf, $size_left ) ; +# my $read_cnt = sysread( $read_fh, my $buf, $size_left ) ; - unless ( defined $read_cnt ) { +# unless ( defined $read_cnt ) { -# handle the read error +# # handle the read error - @_ = ( \%args, "read_file '$file_name' - sysread: $!"); - goto &_error ; - } +# @_ = ( \%args, "read_file '$file_name' - small2 sysread: $!"); +# goto &_error ; +# } - return $buf ; - } +# return $buf ; +# } # infinite read loop. we exit when we are done slurping @@ -220,7 +214,7 @@ ERR # handle the read error - @_ = ( \%args, "read_file '$file_name' - sysread: $!"); + @_ = ( \%args, "read_file '$file_name' - loop sysread: $!"); goto &_error ; }