Problem
Several tied filehandle methods return incorrect values on error, diverging from real Perl I/O:
syswrite (WRITE) returns 0 instead of undef on error
Real syswrite returns undef on all error conditions. The tied WRITE method was returning 0 for:
- EBADF (writing to a read-only handle)
- EINVAL (non-numeric length, negative length, offset outside string)
- EBADF (mock data destroyed via weakref)
This makes errors indistinguishable from "wrote 0 bytes" when checking defined(syswrite(...)).
sysread (READ) returns 0 instead of undef on EBADF
When mock data is destroyed (weakref gone), READ returned 0 (which means EOF) instead of undef (which means error). Code that distinguishes EOF from errors via defined() gets the wrong answer.
getc (GETC) and readline (READLINE) don't set $! = EBADF
On write-only handles, both methods correctly warn "Filehandle opened only for output" but don't set $! = EBADF. Real Perl sets errno in addition to the warning.
Fix
PR #350
🤖 Created by Kōan from audit session