summaryrefslogtreecommitdiffstats
path: root/MDK/Common/System.pm
diff options
context:
space:
mode:
authorPascal Rigaux <pixel@mandriva.com>2004-09-06 06:47:23 +0000
committerPascal Rigaux <pixel@mandriva.com>2004-09-06 06:47:23 +0000
commitf3f2db4239f6839fddc1a056dabbc8899ebcc2b9 (patch)
tree426c8c58e336ad546c6ef0da0a331fd4edd82d88 /MDK/Common/System.pm
parent7312e36856bb7bf9c3261f3791bfe1b24885c639 (diff)
downloadperl-MDK-Common-f3f2db4239f6839fddc1a056dabbc8899ebcc2b9.tar
perl-MDK-Common-f3f2db4239f6839fddc1a056dabbc8899ebcc2b9.tar.gz
perl-MDK-Common-f3f2db4239f6839fddc1a056dabbc8899ebcc2b9.tar.bz2
perl-MDK-Common-f3f2db4239f6839fddc1a056dabbc8899ebcc2b9.tar.xz
perl-MDK-Common-f3f2db4239f6839fddc1a056dabbc8899ebcc2b9.zip
more flexible typeFromMagic
Diffstat (limited to 'MDK/Common/System.pm')
-rw-r--r--MDK/Common/System.pm21
1 files changed, 13 insertions, 8 deletions
diff --git a/MDK/Common/System.pm b/MDK/Common/System.pm
index 427a9e5..7a6d194 100644
--- a/MDK/Common/System.pm
+++ b/MDK/Common/System.pm
@@ -226,18 +226,23 @@ sub compat_arch { better_arch(arch(), $_[0]) }
sub typeFromMagic {
my $f = shift;
- local *F; sysopen F, $f, 0 or return;
+ sysopen(my $F, $f, 0) or return;
my $tmp;
M: foreach (@_) {
- my ($name, @l) = @$_;
- while (@l) {
- my ($offset, $signature) = splice(@l, 0, 2);
- sysseek(F, $offset, 0) or next M;
- sysread(F, $tmp, length $signature);
- $tmp eq $signature or next M;
+ if (ref($_) eq 'CODE') {
+ my $name = $_->($F) or next M;
+ return $name;
+ } else {
+ my ($name, @l) = @$_;
+ while (@l) {
+ my ($offset, $signature) = splice(@l, 0, 2);
+ sysseek($F, $offset, 0) or next M;
+ sysread($F, $tmp, length $signature);
+ $tmp eq $signature or next M;
+ }
+ return $name;
}
- return $name;
}
undef;
}