develooper Front page | perl.perl5.porters | Postings from April 2007

[PATCH] fixed Fcntl::S_IFMT() breakage introduced by change 30674 (blead 26701)

Thread Next
From:
Alexey Tourbin
Date:
April 25, 2007 07:13
Subject:
[PATCH] fixed Fcntl::S_IFMT() breakage introduced by change 30674 (blead 26701)
Message ID:
20070425141222.GA24828@solemn.turbinal
$ perl -MFcntl=:mode -le 'print S_IFMT()'
_S_IFMT
$

Reported by Dmitry V. Levin.
---
 MANIFEST           |    1 +
 ext/Fcntl/Fcntl.pm |   22 ++++++++++++----------
 ext/Fcntl/t/mode.t |   17 +++++++++++++++++
 3 files changed, 30 insertions(+), 10 deletions(-)
 create mode 100644 ext/Fcntl/t/mode.t

diff --git a/MANIFEST b/MANIFEST
index a05471c..7e71a87 100644
--- a/MANIFEST
+++ b/MANIFEST
@@ -589,6 +589,7 @@ ext/Fcntl/Fcntl.pm	Fcntl extension Perl module
 ext/Fcntl/Fcntl.xs	Fcntl extension external subroutines
 ext/Fcntl/Makefile.PL	Fcntl extension makefile writer
 ext/Fcntl/t/fcntl.t	See if Fcntl works
+ext/Fcntl/t/mode.t	See if S_ISREG() and S_ISDIR() work
 ext/Fcntl/t/syslfs.t	See if large files work for sysio
 ext/File/Glob/bsd_glob.c	File::Glob extension run time code
 ext/File/Glob/bsd_glob.h	File::Glob extension header file
diff --git a/ext/Fcntl/Fcntl.pm b/ext/Fcntl/Fcntl.pm
index 067c061..eba5ac4 100644
--- a/ext/Fcntl/Fcntl.pm
+++ b/ext/Fcntl/Fcntl.pm
@@ -55,6 +55,7 @@ See L<perlfunc/stat> about the S_I* constants.
 
 =cut
 
+use strict;
 our($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS, $AUTOLOAD);
 
 require Exporter;
@@ -214,18 +215,18 @@ BEGIN {
   XSLoader::load 'Fcntl', $VERSION;
 }
 
-sub S_IFMT  { @_ ? ( $_[0] & _S_IFMT ) : _S_IFMT  }
+sub S_IFMT  { @_ ? ( $_[0] & _S_IFMT() ) : _S_IFMT()  }
 sub S_IMODE { $_[0] & 07777 }
 
-sub S_ISREG    { ( $_[0] & _S_IFMT ) == S_IFREG   }
-sub S_ISDIR    { ( $_[0] & _S_IFMT ) == S_IFDIR   }
-sub S_ISLNK    { ( $_[0] & _S_IFMT ) == S_IFLNK   }
-sub S_ISSOCK   { ( $_[0] & _S_IFMT ) == S_IFSOCK  }
-sub S_ISBLK    { ( $_[0] & _S_IFMT ) == S_IFBLK   }
-sub S_ISCHR    { ( $_[0] & _S_IFMT ) == S_IFCHR   }
-sub S_ISFIFO   { ( $_[0] & _S_IFMT ) == S_IFIFO   }
-sub S_ISWHT    { ( $_[0] & _S_IFMT ) == S_IFWHT   }
-sub S_ISENFMT  { ( $_[0] & _S_IFMT ) == S_IFENFMT }
+sub S_ISREG    { ( $_[0] & _S_IFMT() ) == S_IFREG()   }
+sub S_ISDIR    { ( $_[0] & _S_IFMT() ) == S_IFDIR()   }
+sub S_ISLNK    { ( $_[0] & _S_IFMT() ) == S_IFLNK()   }
+sub S_ISSOCK   { ( $_[0] & _S_IFMT() ) == S_IFSOCK()  }
+sub S_ISBLK    { ( $_[0] & _S_IFMT() ) == S_IFBLK()   }
+sub S_ISCHR    { ( $_[0] & _S_IFMT() ) == S_IFCHR()   }
+sub S_ISFIFO   { ( $_[0] & _S_IFMT() ) == S_IFIFO()   }
+sub S_ISWHT    { ( $_[0] & _S_IFMT() ) == S_IFWHT()   }
+sub S_ISENFMT  { ( $_[0] & _S_IFMT() ) == S_IFENFMT() }
 
 sub AUTOLOAD {
     (my $constname = $AUTOLOAD) =~ s/.*:://;
@@ -235,6 +236,7 @@ sub AUTOLOAD {
         my (undef,$file,$line) = caller;
         die "$error at $file line $line.\n";
     }
+    no strict 'refs';
     *$AUTOLOAD = sub { $val };
     goto &$AUTOLOAD;
 }
diff --git a/ext/Fcntl/t/mode.t b/ext/Fcntl/t/mode.t
new file mode 100644
index 0000000..57135f6
--- /dev/null
+++ b/ext/Fcntl/t/mode.t
@@ -0,0 +1,17 @@
+#!./perl -w
+
+BEGIN {
+    chdir 't' if -d 't';
+    @INC = '../lib';
+    require './test.pl';
+}
+
+plan tests => 2;
+
+use File::Temp;
+use Fcntl qw(:mode);
+
+my $tmpfile = File::Temp->new;
+my $mode = (stat "$tmpfile")[2];
+ok( S_ISREG($mode), " S_ISREG tmpfile");
+ok(!S_ISDIR($mode), "!S_ISDIR tmpfile");
-- 
1.5.1.1.GIT


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About