I've done some debugging to find out why I get this behaiviour.
I've compiled a vanilla perl 5.8.5 with -O0 -g as cflags. It gives the same output as I've shown in the OP.
I've found that $! is directly connected to errno, and so I've put a watchpoint to errno, and found that errno is set to EBADF by the PerlIO_fast_gets function:
The complete traceback is:int PerlIO_fast_gets(PerlIO *f) { if (PerlIOValid(f) && (PerlIOBase(f)->flags & PERLIO_F_FASTGETS)) +{ PerlIO_funcs *tab = PerlIOBase(f)->tab; if (tab) return (tab->Set_ptrcnt != NULL); SETERRNO(EINVAL, LIB_INVARG); } else SETERRNO(EBADF, SS_IVCHAN); // <---- return 0; }
#0 PerlIO_fast_gets (f=0x817c148) at perlio.c:1721 #1 0x081402e6 in PerlIOBuf_fill (f=0x817ca58) at perlio.c:3576 #2 0x0813da21 in Perl_PerlIO_fill (f=0x817ca58) at perlio.c:1654 #3 0x0813e4ff in PerlIOBase_read (f=0x817ca58, vbuf=0xbfffd657, count +=1) at perlio.c:2059 #4 0x08140498 in PerlIOBuf_read (f=0x817ca58, vbuf=0xbfffd657, count= +1) at perlio.c:3624 #5 0x0813d670 in Perl_PerlIO_read (f=0x817ca58, vbuf=0xbfffd657, coun +t=1) at perlio.c:1564 #6 0x08141f06 in PerlIO_getc (f=0x817ca58) at perlio.c:4771 #7 0x080deb25 in Perl_sv_gets (sv=0x818513c, fp=0x817ca58, append=0) +at sv.c:6341 #8 0x080cd19b in Perl_do_readline () at pp_hot.c:1588 #9 0x080c8cbb in Perl_pp_readline () at pp_hot.c:231 #10 0x080b32da in Perl_runops_debug () at dump.c:1442 #11 0x080624c0 in S_run_body (oldscope=1) at perl.c:1924 #12 0x08062053 in perl_run (my_perl=0x8175e70) at perl.c:1843 #13 0x0805e5f4 in main (argc=2, argv=0xbffffa04, env=0xbffffa10) at pe +rlmain.c:86
I am not a master of perlio (nor of any other part of perl source), so this still doesn't say much to me, but I hope one of you could help me.
In reply to Re: readline succeeds but sets $! = EBADF
by ambrus
in thread readline succeeds but sets $! = EBADF
by ambrus
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |