develooper Front page | perl.perl5.porters | Postings from August 2009

Re: [PATCH] t/io/errno.t + Difference between stdio and perlio?

Thread Previous
Stepan Kasal
August 3, 2009 08:36
Re: [PATCH] t/io/errno.t + Difference between stdio and perlio?
Message ID:
Hello Bram,
I wrote errno.t, and I have to admit I did it poorly.

My original inspiration came from Fedora bug report
which, in turn, followed the example from the description of
"readline" in perlfunc.

That example has for long time adviced to check $! if readline fails.

Actually, that was not right.  As I understand it now, readline is
modelled after the C function getc() and friends, which return EOF
if there is an end-of-file or error.

So in C, you call getc() first.  If it fails, you call feof().
(feof never touches errno.)  If there is not an eof, then errno
indicates what error happened.

Following this analogy, it seems that the example for readline should
be modified like this:

    for (;;) {
        ##undef $!;
        unless (defined( $line = <> )) {
            last if eof;
            die $! ; ##if $!;
        # ...

Observe that I propose to remove the "undef" and "$!"; if there in
not an eof, the readline is oblidged to set $!.

The only forbidden combination is when neither eof nor the $! is set.
We could check for that in errno.t:

my $test_prog = 'for(;;){undef($!); if(defined($_=<>)) {print} else {last}};
                if(!eof) {die ($!=="" ? "Undefined \$!" : $!)}';

But is there really any danger that this would happen?
If not we might simply delete t/io/errno.t completely.

Have a nice day,
Stepan Kasal

Thread Previous Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About