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:

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; }
The complete traceback is:
#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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.