Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/Test/MockFile/FileHandle.pm
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,7 @@ sub SEEK {
}

if ( $new_pos < 0 ) {
$! = EINVAL;
return 0;
}

Expand Down
6 changes: 6 additions & 0 deletions t/seek.t
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ my $content = "ABCDEFGHIJ";

is( sysseek( $fh, 11, SEEK_SET ), 11, "SEEK_SET beyond EOF succeeds (POSIX allows seeking past end)" );

$! = 0;
is( sysseek( $fh, -1, SEEK_SET ), 0, "SEEK_SET to negative returns 0 (failure)" );
is( $! + 0, EINVAL, "SEEK_SET to negative sets \$! to EINVAL" );

close $fh;
}
Expand All @@ -56,7 +58,9 @@ my $content = "ABCDEFGHIJ";
is( sysseek( $fh, 0, SEEK_CUR ), 6, "SEEK_CUR 0 returns current position (6)" );

# Try to seek before start of file
$! = 0;
is( sysseek( $fh, -100, SEEK_CUR ), 0, "SEEK_CUR before start of file returns 0" );
is( $! + 0, EINVAL, "SEEK_CUR before start sets \$! to EINVAL" );

# Try to seek beyond EOF
is( sysseek( $fh, 100, SEEK_CUR ), 106, "SEEK_CUR beyond EOF succeeds (position 6 + 100 = 106)" );
Expand All @@ -79,7 +83,9 @@ my $content = "ABCDEFGHIJ";

is( sysseek( $fh, -10, SEEK_END ), "0 but true", "SEEK_END -10 gives position 0 ('0 but true')" );

$! = 0;
is( sysseek( $fh, -11, SEEK_END ), 0, "SEEK_END before start returns 0 (failure)" );
is( $! + 0, EINVAL, "SEEK_END before start sets \$! to EINVAL" );

is( sysseek( $fh, 1, SEEK_END ), 11, "SEEK_END +1 beyond file succeeds (10 + 1 = 11)" );

Expand Down
Loading