... among other things: https://rt.perl.org/Ticket/Display.html?id=122021
PerlIO::scalar (aka opening scalars for IO) has fileno of -1.
This (and probably other exotic PerlIO objects which have funny fds)
requires special care.
PL_laststype = OP_STAT;
PL_statgv = gv ? gv : (GV *)io;
sv_setpvs(PL_statname, "");
- if(io) {
+ if (io) {
if (IoIFP(io)) {
int fd = PerlIO_fileno(IoIFP(io));
- if (fd >= 0) {
+ if (fd < 0) {
+ /* E.g. PerlIO::scalar has no real fd. */
+ return (PL_laststatval = -1);
+ } else {
return (PL_laststatval = PerlLIO_fstat(fd, &PL_statcache));
}
} else if (IoDIRP(io)) {