From 122900cfb1ffa8da75d3a1d09f25075460cda70f Mon Sep 17 00:00:00 2001 From: Toddr Bot Date: Tue, 31 Mar 2026 21:42:12 +0000 Subject: [PATCH 1/2] test: verify seek() sets $! to EINVAL on negative position Add assertions that $! is set to EINVAL when seek results in a negative file position. These tests currently fail, demonstrating the bug reported in issue #342. Co-Authored-By: Claude Opus 4.6 --- t/seek.t | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/t/seek.t b/t/seek.t index 3789128..a06637e 100644 --- a/t/seek.t +++ b/t/seek.t @@ -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; } @@ -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)" ); @@ -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)" ); From 0c923f33ecfc5061f90b0fc9a4ae03a7a5c9ef11 Mon Sep 17 00:00:00 2001 From: Toddr Bot Date: Tue, 31 Mar 2026 21:43:03 +0000 Subject: [PATCH 2/2] fix: set $! to EINVAL when seek() results in negative position Real Perl's seek() sets $! to EINVAL when the resulting file position would be negative. The mock SEEK method was correctly returning 0 (failure) but forgot to set the errno. Fixes #342. Co-Authored-By: Claude Opus 4.6 --- lib/Test/MockFile/FileHandle.pm | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/Test/MockFile/FileHandle.pm b/lib/Test/MockFile/FileHandle.pm index b857b8a..901ecd0 100644 --- a/lib/Test/MockFile/FileHandle.pm +++ b/lib/Test/MockFile/FileHandle.pm @@ -656,6 +656,7 @@ sub SEEK { } if ( $new_pos < 0 ) { + $! = EINVAL; return 0; }