in reply to Re: Testing for readdir failure (Perl-bug)
in thread Testing for readdir failure

I have been following these contributions with interest, but I do not have the C expertise to understand some of it. So I wonder if you could advise me on these questions:

You now refer to "perlbug errno test without localizing". Could you characterize how this bug shows up at the Perl (as opposed to the C) level? Is the answer just "readdir sometimes throws warnings and sometimes not", or can it be made more explicit?

In addition to "use warnings", is the following the best I can do for discovering that a problem occurred during a readdir? If not, what would be better?

$! = undef; @a = readdir(D); if ( defined($!) ) { # Process a readdir error }

Finally, will this bug modify how "effective" this code is in recognizing the occurrence of an error on the readdir?

Thanks very much for all your help.

Replies are listed 'Best First'.
Re^3: Testing for readdir failure (Perl-bug)
by rdiez (Acolyte) on Jun 29, 2020 at 14:09 UTC
Re^3: Testing for readdir failure (Perl-bug)
by LanX (Saint) on May 27, 2013 at 21:50 UTC
    I can't neither help you on the C-level, Perl source code is very special with all its preprocessor macros.

    (UPDATE. striked nonsense, see reply)

    In the case of readdir the following should help

    $! = undef; @a = readdir(D) or process_errno();

    But in the case of readline it doesn't.

    The other advices I gave you - like catching $SIG{WARN} - are still valid,

    I will post the ticket-link after reporting the perlbug.

    Cheers Rolf

    ( addicted to the Perl Programming Language)

      @a = readdir(D) or process_errno();

      So you are assuming, if for example an I/O error occurs while the directory is being read, that the result of readdir will be an empty (or undefined) directory. Is that guaranteed to be true? It seemed to me that it might instead provide as much of the directory as it successfully read.

        Ups sorry I was in a hurry!

        Of course you're right this is nonsense!

        I just copied the open() || die pattern, even with the wrong or operator.

        Forget what I said, your version of testing '$!' in the next line should be fine!

        Cheers Rolf

        ( addicted to the Perl Programming Language)