zdm has asked for the wisdom of the Perl Monks concerning the following question:
According to the documentation of the "stat" function we can use Fcntl::S_IFMT($mode) call, where $mode is $stat2.
Results of the Fcntl::S_IFMT($mode) can be bit-anded with the various constants (S_IFREG, S_IFDIR, S_IFLNK, S_IFBLK, S_IFCHR, S_IFIFO, S_IFSOCK, S_IFWHT, S_ENFMT) to determine file type.
So, my question is - why last test returns TRUE?
'/etc/passwd' - is a regular file (not a link), and first two tests confirms this.
But last test says, that '/etc/passwd' is a link.
#!/usr/bin/env perl use strict; use warnings; use Fcntl qw[]; my $path = '/etc/passwd'; my @stat = stat $path or die $!; printf "%s\n", -l $path ? 1 : 0; # 0 - OK, not a link printf "%s\n", Fcntl::S_ISLNK( $stat[2] ) ? 1 : 0; # 0 - OK, not a +link printf "%s\n", Fcntl::S_IFMT( $stat[2] ) & Fcntl::S_IFLNK ? 1 : 0; +# 1 - ERROR __END__
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Unexpected Fcntl::S_IFLNK behavior
by Corion (Patriarch) on Oct 01, 2018 at 21:10 UTC | |
by zdm (Beadle) on Oct 01, 2018 at 21:38 UTC | |
by Corion (Patriarch) on Oct 01, 2018 at 22:23 UTC | |
by zdm (Beadle) on Oct 02, 2018 at 09:39 UTC | |
|
Re: Unexpected Fcntl::S_IFLNK behavior
by stevieb (Canon) on Oct 01, 2018 at 20:47 UTC |