Skip to content

fix: set $! to EINVAL on negative seek position#343

Draft
toddr-bot wants to merge 2 commits intocpan-authors:mainfrom
toddr-bot:koan.toddr.bot/fix-seek-einval
Draft

fix: set $! to EINVAL on negative seek position#343
toddr-bot wants to merge 2 commits intocpan-authors:mainfrom
toddr-bot:koan.toddr.bot/fix-seek-einval

Conversation

@toddr-bot
Copy link
Copy Markdown
Collaborator

What

Sets $! to EINVAL when seek() results in a negative file position.

Why

Real Perl's seek() sets $! to EINVAL when the resulting position would be negative. The mock SEEK method was returning 0 (failure) correctly but not setting errno, causing code that checks $! after a failed seek to get stale or wrong error codes. Fixes #342.

How

One-line addition: $! = EINVAL before return 0 in the negative-position guard of FileHandle::SEEK.

Testing

  • Added 3 EINVAL assertions to t/seek.t (one per whence mode: SEEK_SET, SEEK_CUR, SEEK_END)
  • First commit adds failing tests, second commit applies the fix (two-commit pattern)
  • Full test suite passes (66/66 seek tests, 1589 total — only pre-existing fh-ref-leak.t failure)

🤖 Generated with Claude Code

toddr-bot and others added 2 commits March 31, 2026 21:42
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 cpan-authors#342.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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 cpan-authors#342.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: seek() to negative position doesn't set $! to EINVAL

1 participant