Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re^3: Testing for a directory handle

by syphilis (Archbishop)
on Jan 29, 2018 at 05:06 UTC ( [id://1208023]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Testing for a directory handle
in thread Testing for a directory handle

The dirfd function is unimplemented

This only happens (for me) if the handle is a dirhandle:
C:\_32>perl -le "opendir $rd, 'special' or die $!; print 'dir' if -d $ +rd; print 'file' if -f $rd;" The dirfd function is unimplemented at -e line 1. C:\_32>perl -le "opendir RD, 'special' or die $!; print 'dir' if -d RD +; print 'file' if -f RD;" The dirfd function is unimplemented at -e line 1. C:\_32>perl -le "opendir RD, 'special' or die $!; print 'dir' if -d \* +RD; print 'file' if -f \*RD;" The dirfd function is unimplemented at -e line 1.

With a filehandle it seems fine:
C:\_32>perl -le "open $rd, 'try.pl' or die $!; print 'dir' if -d $rd; +print 'file' if -f $rd;" file C:\_32>perl -le "open RD, 'try.pl' or die $!; print 'dir' if -d RD; pr +int 'file' if -f RD;" file C:\_32>perl -le "open RD, 'try.pl' or die $!; print 'dir' if -d \*RD; +print 'file' if -f \*RD;" file
Surely this behaviour with dirhandles is a serious bug that should be reported to p5p ?
I can see nothing in the -X documentation that allows such behaviour, and I can see plenty there that disallows it.

Cheers,
Rob

Replies are listed 'Best First'.
Re^4: Testing for a directory handle
by ns550 (Novice) on Jan 29, 2018 at 05:24 UTC

    I will send an email to perlbug@perl.org with a link to this post

      I will send an email to perlbug@perl.org

      The error message first appears in perl-5.8.9.
      In 5.8.8 (and probably earlier) -f and -d calls on a directory inevitably returned false, without warning or error.
      So I guess that making them fatal and providing a relevant error message was just their way of dealing with what is apparently an issue specific to Windows.
      (No such problem exists on Linux.)

      So ... I'm not sure that the porters will be all that keen to do anything about this shortcoming - in which case the bug is in the documentation. We'll just have to wait and see.
      If it's not something that's going to be fixed then it's something that, along with its workaround, should be prominently documented in both the perlport and the -X docs.

      The Windows workaround to -d HANDLE that comes to my mind is that you do:
      eval{-d $handle}; if($@ =~ /dirfd function is unimplemented/) { # then you know $handle is a dirhandle } elsif($@) { die $@; # a different problem } else { # it's safe to call -X on $handle }
      But others might know of better workarounds.

      Cheers,
      Rob

        Yes, I agree

        It should be documented and/or fixed if possible. It could just be added to the list of port issues on https://perldoc.perl.org/perlport.html#-X. But it would be nice if it worked properly as it is a core function.

        I will keep these work-arounds in mind when I am coding. Thanks, Matt

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1208023]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (5)
As of 2024-04-24 06:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found