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

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

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

My original inspiration came from Fedora bug report
http://bugzilla.redhat.com/231113
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


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About