diff --git a/bin/ls b/bin/ls index dbbfc46a..08132313 100755 --- a/bin/ls +++ b/bin/ls @@ -150,9 +150,8 @@ sub DirEntries { my @Entries = (); # entries in original order my $Name = ""; # entry name - if (!opendir($dh, $_[0]) || exists($Options{'d'})) { + if (exists $Options{'d'} || ! -d $_[0]) { if (-e $_[0]) { - closedir($dh) if (defined($dh)); push(@Entries, $_[0]); $Attributes{$_[0]} = stat($_[0]); push(@Entries, \%Attributes); @@ -161,6 +160,10 @@ sub DirEntries { warn "$Program: can't access '$_[0]': $!\n"; return (); } + unless (opendir $dh, $_[0]) { + warn "$Program: failed to open directory '$_[0]': $!\n"; + return (); + } while ($Name = readdir($dh)) { next if (!exists($Options->{'a'}) && $Name =~ m/^\./o);