develooper Front page | perl.perl5.porters | Postings from November 2004

[perl #31730] IO::File reads garbage from directory filehandles

Thread Previous
From:
Steve Peters via RT
Date:
November 27, 2004 07:36
Subject:
[perl #31730] IO::File reads garbage from directory filehandles
Message ID:
rt-3.0.11-31730-101121.1.60230406902777@perl.org
> [ni-s - Thu Sep 30 14:34:10 2004]:
> 
> Steve Peters via RT <perlbug-followup@perl.org> writes:
> >
> >Two points brought up remain, though.
> >
> >* Do we want to add an optional argument to IO::File->new() so that it 
> >fails on an open attempt on a directory?  The advantage of this would 
> >be that it would allow for consistant cross-platform behavior.  This 
> >would add some overhead to IO::File (likely a -d) to the constructor 
> >for IO::File.
> 
> >
> >* Do we want to document this behavior?  Those who have bounced around 
> >several POSIX environments have experienced this before and have 
> >learned to deal with this behavior.  Does this deserve mention on 
> >IO::File's Pod, or is a FAQ entry sufficient?   
> 
> Personally I see no reason to use IO::File ever again so I don't care 
> what you do to it, or its POD.
> 
> I see some minor merit in mentioning amongst all the other 
> perldoc -f open stuff.
> As for a FAQ entry, I don't remember this coming up 
> before and I have been on p5p for (9?!) years so this isn't 
> a very 'F' 'AQ'!
> 

Below is a patch to explain the behavior and to suggest better alternatives.

--- /usr/libdata/perl5/i386-openbsd/5.8.5/IO/File.pm    Fri Sep 17
13:09:59 2004
+++ ./IO/File.pm        Sat Nov 27 09:32:46 2004
@@ -95,12 +95,20 @@
 
 =back
 
+=head1 NOTE
+
+Some operating systems may allow a C<IO::File::new> or C<IO::File::open> 
+to be performed on a directory without errors.  This behavior is not
+portable and not suggested for use.  Instead, C<opendir> and C<readdir> or
+C<DirHandle> suggested instead.
+
 =head1 SEE ALSO
 
 L<perlfunc>, 
 L<perlop/"I/O Operators">,
 L<IO::Handle>
 L<IO::Seekable>
+L<DirHandle>
 
 =head1 HISTORY
 
@@ -121,7 +129,7 @@
 
 @ISA = qw(IO::Handle IO::Seekable Exporter);
 
-$VERSION = "1.10";
+$VERSION = "1.11";
 
 @EXPORT = @IO::Seekable::EXPORT;
 


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