line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Copyrights 2011-2020 by [Mark Overmeer]. |
2
|
|
|
|
|
|
|
# For other contributors see ChangeLog. |
3
|
|
|
|
|
|
|
# See the manual pages for details on the licensing terms. |
4
|
|
|
|
|
|
|
# Pod stripped from pm file by OODoc 2.02. |
5
|
|
|
|
|
|
|
# This code is part of distribution POSIX-1003. Meta-POD processed with |
6
|
|
|
|
|
|
|
# OODoc into POD and HTML manual-pages. See README.md |
7
|
|
|
|
|
|
|
# Copyright Mark Overmeer. Licensed under the same terms as Perl itself. |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
package POSIX::1003::FS; |
10
|
5
|
|
|
5
|
|
216079
|
use vars '$VERSION'; |
|
5
|
|
|
|
|
40
|
|
|
5
|
|
|
|
|
330
|
|
11
|
|
|
|
|
|
|
$VERSION = '1.02'; |
12
|
|
|
|
|
|
|
|
13
|
5
|
|
|
5
|
|
32
|
use base 'POSIX::1003::Module'; |
|
5
|
|
|
|
|
6
|
|
|
5
|
|
|
|
|
1456
|
|
14
|
|
|
|
|
|
|
|
15
|
5
|
|
|
5
|
|
35
|
use warnings; |
|
5
|
|
|
|
|
31
|
|
|
5
|
|
|
|
|
148
|
|
16
|
5
|
|
|
5
|
|
26
|
use strict; |
|
5
|
|
|
|
|
8
|
|
|
5
|
|
|
|
|
2012
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
my (@constants, @access, @stat, @glob); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
# POSIX.xs defines L_ctermid L_cuserid L_tmpname: useless! |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
my @functions = qw/ |
23
|
|
|
|
|
|
|
mkfifo mknod stat lstat rename |
24
|
|
|
|
|
|
|
access lchown |
25
|
|
|
|
|
|
|
utime |
26
|
|
|
|
|
|
|
major minor makedev |
27
|
|
|
|
|
|
|
/; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
our @IN_CORE = qw(utime mkdir stat lstat rename); |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
our %EXPORT_TAGS = |
32
|
|
|
|
|
|
|
( constants => \@constants |
33
|
|
|
|
|
|
|
, functions => \@functions |
34
|
|
|
|
|
|
|
, access => \@access |
35
|
|
|
|
|
|
|
, stat => \@stat |
36
|
|
|
|
|
|
|
, glob => \@glob |
37
|
|
|
|
|
|
|
, tables => [ qw/%access %stat/ ] |
38
|
|
|
|
|
|
|
); |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
my ($fsys, %access, %stat, %glob); |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
BEGIN |
43
|
5
|
|
|
5
|
|
392
|
{ $fsys = fsys_table; |
44
|
5
|
|
|
|
|
101
|
push @constants, keys %$fsys; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
# initialize the :access export tag |
47
|
5
|
|
|
|
|
24
|
@access = qw/access/; |
48
|
5
|
|
|
|
|
215
|
push @access, grep /_OK$|MAX/, keys %$fsys; |
49
|
5
|
|
|
|
|
28
|
my %access_subset; |
50
|
5
|
|
|
|
|
8
|
@access_subset{@access} = @{$fsys}{@access}; |
|
5
|
|
|
|
|
30
|
|
51
|
5
|
|
|
|
|
36
|
tie %access, 'POSIX::1003::ReadOnlyTable', \%access_subset; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
# initialize the :stat export tag |
54
|
5
|
|
|
|
|
18
|
@stat = qw/stat lstat mkfifo mknod mkdir lchown |
55
|
|
|
|
|
|
|
S_ISDIR S_ISCHR S_ISBLK S_ISREG S_ISFIFO S_ISLNK S_ISSOCK S_ISWHT |
56
|
|
|
|
|
|
|
/; |
57
|
5
|
|
|
|
|
143
|
push @stat, grep /^S_I/, keys %$fsys; |
58
|
5
|
|
|
|
|
20
|
my %stat_subset; |
59
|
5
|
|
|
|
|
8
|
@stat_subset{@stat} = @{$fsys}{@stat}; |
|
5
|
|
|
|
|
80
|
|
60
|
5
|
|
|
|
|
22
|
tie %stat, 'POSIX::1003::ReadOnlyTable', \%stat_subset; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
# initialize the :fsys export tag |
63
|
5
|
|
|
|
|
69
|
@glob = qw/posix_glob fnmatch/; |
64
|
5
|
|
|
|
|
146
|
push @glob, grep /^(?:GLOB|FNM|WRDE)_/, keys %$fsys; |
65
|
5
|
|
|
|
|
19
|
my %glob_subset; |
66
|
5
|
|
|
|
|
8
|
@glob_subset{@glob} = @{$fsys}{@glob}; |
|
5
|
|
|
|
|
49
|
|
67
|
5
|
|
|
|
|
20
|
tie %glob, 'POSIX::1003::ReadOnlyTable', \%glob_subset; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
|
71
|
0
|
|
|
0
|
1
|
0
|
sub S_ISDIR($) { ($_[0] & S_IFMT()) == S_IFDIR()} |
72
|
0
|
|
|
0
|
1
|
0
|
sub S_ISCHR($) { ($_[0] & S_IFMT()) == S_IFCHR()} |
73
|
0
|
|
|
0
|
1
|
0
|
sub S_ISBLK($) { ($_[0] & S_IFMT()) == S_IFBLK()} |
74
|
0
|
|
|
0
|
1
|
0
|
sub S_ISREG($) { ($_[0] & S_IFMT()) == S_IFREG()} |
75
|
0
|
|
|
0
|
1
|
0
|
sub S_ISFIFO($) { ($_[0] & S_IFMT()) == S_IFIFO()} |
76
|
0
|
|
|
0
|
1
|
0
|
sub S_ISLNK($) { ($_[0] & S_IFMT()) == S_IFLNK()} |
77
|
0
|
|
|
0
|
1
|
0
|
sub S_ISSOCK($) { ($_[0] & S_IFMT()) == S_IFSOCK()} |
78
|
0
|
|
|
0
|
1
|
0
|
sub S_ISWHT($) { ($_[0] & S_IFMT()) == S_IFWHT()} # FreeBSD |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub lchown($$@) |
82
|
0
|
|
|
0
|
1
|
0
|
{ my ($uid, $gid) = (shift, shift); |
83
|
0
|
|
|
|
|
0
|
my $successes = 0; |
84
|
0
|
|
0
|
|
|
0
|
POSIX::lchown($uid, $gid, $_) && $successes++ for @_; |
85
|
0
|
|
|
|
|
0
|
$successes; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub posix_glob($%) |
90
|
5
|
|
|
5
|
0
|
2994
|
{ my ($patterns, %args) = @_; |
91
|
|
|
|
|
|
|
my $flags = $args{flags} |
92
|
5
|
|
66
|
|
|
37
|
// $glob{GLOB_NOSORT}|$glob{GLOB_NOESCAPE}|$glob{GLOB_BRACE}; |
93
|
5
|
|
100
|
0
|
|
31
|
my $errfun = $args{on_error} || sub {0}; |
|
0
|
|
|
|
|
0
|
|
94
|
|
|
|
|
|
|
|
95
|
5
|
|
|
|
|
8
|
my ($err, @fns); |
96
|
5
|
50
|
|
|
|
14
|
if(ref $patterns eq 'ARRAY') |
97
|
0
|
|
|
|
|
0
|
{ foreach my $pattern (@$patterns) |
98
|
0
|
|
|
|
|
0
|
{ my $thiserr = _glob(@fns, $pattern, $flags, $errfun); |
99
|
0
|
0
|
0
|
|
|
0
|
next if !$thiserr || $thiserr==$glob{GLOB_NOMATCH}; |
100
|
|
|
|
|
|
|
|
101
|
0
|
|
|
|
|
0
|
$err = $thiserr; |
102
|
0
|
|
|
|
|
0
|
last; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
else |
106
|
5
|
|
|
|
|
357
|
{ $err = _glob(@fns, $patterns, $flags, $errfun); |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
5
|
50
|
33
|
|
|
28
|
if($args{unique} && @fns) |
110
|
0
|
|
|
|
|
0
|
{ my %seen; |
111
|
0
|
|
|
|
|
0
|
@fns = grep !$seen{$_}++, @fns; |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
5
|
0
|
33
|
|
|
10
|
$err //= @fns ? $glob{GLOB_NOMATCH} : 0; |
115
|
5
|
|
|
|
|
43
|
($err, \@fns); |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
sub fnmatch($$;$) |
120
|
2
|
|
|
2
|
1
|
934
|
{ my ($pat, $name, $flags) = @_; |
121
|
2
|
|
50
|
|
|
28
|
_fnmatch($pat, $name, $flags//0); |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
#--------- |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
sub _create_constant($) |
127
|
84
|
|
|
84
|
|
122
|
{ my ($class, $name) = @_; |
128
|
84
|
|
|
|
|
99
|
my $val = $fsys->{$name}; |
129
|
84
|
|
|
0
|
|
504
|
sub() {$val}; |
|
0
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
1; |