blib/lib/POSIX/1003/Fcntl.pm

filter: Statementstmt 50.8% 61 / 120 Branchbran 17.6% 12 / 68 Conditioncond 20.0% 9 / 45 MC/DCmcdc 0.0% 0 / 26 Subroutinesub 46.4% 13 / 28 Podpod 100% 18 / 18 totaltotal 37.0% 113 / 305 CC 54 SCAR 34.6
CC
54
Cov
35%
setfd_owner
132.0
getfd_owner
72.0
setfd_lock
16.4
CRAP 31.8
« manuals.PL ↑ Summary blib/lib/POSIX/1003/Module.pm »
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::Fcntl;
10 6 ▶use vars '$VERSION';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 6 $VERSION = '1.02';
12  
13 6 ▶use base 'POSIX::1003::Module';
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 6 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 6 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 6 ▶use POSIX::1003::FdIO qw/SEEK_SET O_CLOEXEC/;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 6 ▶use POSIX::1003::Errno qw/ENOSYS/;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 6 my @constants;
22 6 my @functions = qw/fcntl
23 fcntl_dup
24 getfd_control
25 setfd_control
26 getfd_flags
27 setfd_flags
28 setfd_lock
29 getfd_islocked
30 getfd_owner
31 setfd_owner
32 setfd_signal
33 getfd_signal
34 setfd_lease
35 getfd_lease
36 setfd_notify
37 setfd_pipe_size
38 getfd_pipe_size
39  
40 flock
41 flockfd
42  
43 lockf
44 /;
45  
46 6 our %EXPORT_TAGS =
47 ( constants => \@constants
48 , functions => \@functions
49 , flock => [ qw/flock flockfd LOCK_SH LOCK_EX LOCK_UN LOCK_NB/ ]
50 , lockf => [ qw/lockf F_LOCK F_TLOCK F_ULOCK F_TEST/ ]
51 , tables => [ qw/%fcntl/ ]
52 );
53  
54 6 our @IN_CORE = qw/fcntl flock/;
55  
56 6 my $fcntl;
57  
58 # We need to address all of our own constants via this HASH, because
59 # they will not be available at compile-time of this file.
60 6 our %fcntl;
61  
62 6 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
63 6 $fcntl = fcntl_table;
64 6 push @constants, keys %$fcntl;
65 6 tie %fcntl, 'POSIX::1003::ReadOnlyTable', $fcntl;
66 }
67  
68 # required parameter which does not get used by the OS.
69 6 ▶use constant UNUSED => 0;
Subroutine BEGIN: called CC=1 SCAR=0.0
70  
71  
72 sub flockfd($$)
73 0 ▶{ my ($file, $flags) = @_;
Subroutine flockfd: not called CC=2 SCAR=17.9
Pod documented
74 0 ▶ my $fd = ref $file ? fileno($file) : $file;
Branch: 1 branch
BranchTrueFalseTotal
ref $file ? : 0 0 0
75 0 _flock($fd, $flags);
76 }
77  
78  
79 sub lockf($$;$)
80 0 ▶{ my ($file, $flags, $len) = @_;
Subroutine lockf: not called CC=3 SCAR=24.8
Pod documented
81 0 ▶ my $fd = ref $file ? fileno($file) : $file;
Branch: 1 branch
BranchTrueFalseTotal
ref $file ? : 0 0 0
82 0 ▶ _lockf($fd, $flags, $len//0);
Condition0%0/2
$len // 0
l!l
00
MC/DC0%0/1
$len // 0
$len
Truth table0%0/2
A
A= $len
Aresult
11
00
83 }
84  
85 #---------------
86  
87  
88 sub fcntl_dup($%)
89 2 ▶{ my ($file, %args) = @_;
Subroutine fcntl_dup: called CC=5 SCAR=21.7
Pod documented
90 2 ▶ my $fd = ref $file ? fileno($file) : $file;
Branch: 1 branch
BranchTrueFalseTotal
ref $file ? : 0 2 2
91 2 ▶ my $func = $args{close_on_exec} ? $fcntl->{F_DUPFD_CLOEXEC} : $fcntl->{F_DUPFD};
Branch: 1 branch
BranchTrueFalseTotal
$args{'close_on_exec'} ? : 0 2 2
92  
93 return _fcntl $fd, $fcntl->{F_DUPFD}, UNUSED
94 2 ▶ if !$args{close_on_exec};
Branch: 1 branch
BranchTrueFalseTotal
unless $args{"close_on_exec"} 2 0 2
95  
96 return _fcntl $fd, $fcntl->{F_DUPFD_CLOEXEC}, UNUSED
97 0 ▶ if defined $fcntl->{F_DUPFD_CLOEXEC};
Branch: 1 branch
BranchTrueFalseTotal
if defined $fcntl->{"F_DUPFD_CLOEXEC"} 0 0 0
98  
99 0 _fcntl $fd, $fcntl->{F_DUPFD}, UNUSED;
100 0 setfd_control $fd, O_CLOEXEC;
101 }
102  
103  
104 sub getfd_control($)
105 0 ▶{ my ($file) = @_;
Subroutine getfd_control: not called CC=2 SCAR=17.9
Pod documented
106 0 ▶ my $fd = ref $file ? fileno($file) : $file;
Branch: 1 branch
BranchTrueFalseTotal
ref $file ? : 0 0 0
107 0 _fcntl $fd, $fcntl->{F_GETFD}, UNUSED;
108 }
109  
110  
111  
112 sub setfd_control($$)
113 0 ▶{ my ($file, $flags) = @_;
Subroutine setfd_control: not called CC=2 SCAR=17.9
Pod documented
114 0 ▶ my $fd = ref $file ? fileno($file) : $file;
Branch: 1 branch
BranchTrueFalseTotal
ref $file ? : 0 0 0
115 0 _fcntl $fd, $fcntl->{F_SETFD}, $flags;
116 }
117  
118  
119  
120 sub getfd_flags($)
121 2 ▶{ my ($file) = @_;
Subroutine getfd_flags: called CC=2 SCAR=7.1
Pod documented
122 2 ▶ my $fd = ref $file ? fileno($file) : $file;
Branch: 1 branch
BranchTrueFalseTotal
ref $file ? : 0 2 2
123 2 _fcntl $fd, $fcntl->{F_GETFL}, UNUSED;
124 }
125  
126  
127 sub setfd_flags($$)
128 0 ▶{ my ($file, $flags) = @_;
Subroutine setfd_flags: not called CC=2 SCAR=17.9
Pod documented
129 0 ▶ my $fd = ref $file ? fileno($file) : $file;
Branch: 1 branch
BranchTrueFalseTotal
ref $file ? : 0 0 0
130 0 _fcntl $fd, $fcntl->{F_SETFL}, $flags;
131 }
132  
133  
134  
135 sub setfd_lock($%)
136 2 ▶{ my ($file, %args) = @_;
Subroutine setfd_lock: called CC=10 SCAR=28.0
Pod documented
137 2 ▶ my $fd = ref $file ? fileno($file) : $file;
Branch: 1 branch
BranchTrueFalseTotal
ref $file ? : 0 2 2
138  
139 2 my $func;
140 $func = $args{wait} ? $fcntl->{F_SETLKP} : $fcntl->{F_SETLKWP}
141 2 ▶ if $args{private};
Branch: 2 branches
BranchTrueFalseTotal
if $args{"private"} 0 2 2
$args{'wait'} ? : 0 0 0
142  
143 2 ▶ $func //= $args{wait} ? $fcntl->{F_SETLK} : $fcntl->{F_SETLKW};
Branch: 1 branch
BranchTrueFalseTotal
$args{'wait'} ? : 0 2 2
Condition33%1/3
$func //= $args{"wait"} ? $fcntl->{"F_SETLK"} : $fcntl->{"F_SETLKW"}
l!l&&r!l&&!r
020
MC/DC0%0/2
$func //= $args{"wait"} ? $fcntl->{"F_SETLK"} : $fcntl->{"F_SETLKW"}
$func $args{"wait"} ? $fcntl->{"F_SETLK"} : $fcntl->{"F_SETLKW"}
Truth table33%1/3
A //= B
A= $funcB= $args{"wait"} ? $fcntl->{"F_SETLK"} : $fcntl->{"F_SETLKW"}
ABresult
1X1
011
000
144  
145 2 ▶ $args{type} //= $fcntl->{F_RDLCK};
Condition33%1/3
$args{"type"} //= $fcntl->{"F_RDLCK"}
l!l&&r!l&&!r
200
MC/DC0%0/2
$args{"type"} //= $fcntl->{"F_RDLCK"}
$args{"type"} $fcntl->{"F_RDLCK"}
Truth table33%1/3
A //= B
A= $args{"type"}B= $fcntl->{"F_RDLCK"}
ABresult
1X1
011
000
146 2 ▶ $args{whence} //= SEEK_SET;
Condition50%1/2
$args{"whence"} //= 0
l!l
02
MC/DC0%0/1
$args{"whence"} //= 0
$args{"whence"}
Truth table50%1/2
A
A= $args{"whence"}
Aresult
11
00
147 2 ▶ $args{start} //= 0;
Condition50%1/2
$args{"start"} //= 0
l!l
20
MC/DC0%0/1
$args{"start"} //= 0
$args{"start"}
Truth table50%1/2
A
A= $args{"start"}
Aresult
11
00
148 2 ▶ $args{len} //= 0;
Condition50%1/2
$args{"len"} //= 0
l!l
20
MC/DC0%0/1
$args{"len"} //= 0
$args{"len"}
Truth table50%1/2
A
A= $args{"len"}
Aresult
11
00
149 2 _lock $fd, $func, \%args;
150 }
151  
152  
153  
154 sub getfd_islocked($%)
155 2 ▶{ my ($file, %args) = @_;
Subroutine getfd_islocked: called CC=10 SCAR=27.4
Pod documented
156 2 ▶ my $fd = ref $file ? fileno($file) : $file;
Branch: 1 branch
BranchTrueFalseTotal
ref $file ? : 0 2 2
157 2 ▶ $args{type} //= $fcntl->{F_RDLCK};
Condition33%1/3
$args{"type"} //= $fcntl->{"F_RDLCK"}
l!l&&r!l&&!r
200
MC/DC0%0/2
$args{"type"} //= $fcntl->{"F_RDLCK"}
$args{"type"} $fcntl->{"F_RDLCK"}
Truth table33%1/3
A //= B
A= $args{"type"}B= $fcntl->{"F_RDLCK"}
ABresult
1X1
011
000
158 2 ▶ $args{whence} //= SEEK_SET;
Condition50%1/2
$args{"whence"} //= 0
l!l
02
MC/DC0%0/1
$args{"whence"} //= 0
$args{"whence"}
Truth table50%1/2
A
A= $args{"whence"}
Aresult
11
00
159 2 ▶ $args{start} //= 0;
Condition50%1/2
$args{"start"} //= 0
l!l
20
MC/DC0%0/1
$args{"start"} //= 0
$args{"start"}
Truth table50%1/2
A
A= $args{"start"}
Aresult
11
00
160 2 ▶ $args{len} //= 0;
Condition50%1/2
$args{"len"} //= 0
l!l
20
MC/DC0%0/1
$args{"len"} //= 0
$args{"len"}
Truth table50%1/2
A
A= $args{"len"}
Aresult
11
00
161  
162 2 ▶ my $func = $args{private} ? ($fcntl->{F_GETLKW}//$fcntl->{F_GETLK}) : $fcntl->{F_GETLK};
Branch: 1 branch
BranchTrueFalseTotal
$args{'private'} ? : 0 2 2
Condition0%0/3
$fcntl->{"F_GETLKW"} // $fcntl->{"F_GETLK"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$fcntl->{"F_GETLKW"} // $fcntl->{"F_GETLK"}
$fcntl->{"F_GETLKW"} $fcntl->{"F_GETLK"}
Truth table0%0/3
A // B
A= $fcntl->{"F_GETLKW"}B= $fcntl->{"F_GETLK"}
ABresult
1X1
011
000
163 2 ▶ my $lock = _lock $fd, $func, \%args
Branch: 1 branch
BranchTrueFalseTotal
my $lock = &_lock($fd, $func, \%args) or return undef 2 0 2
164 or return undef;
165  
166 #XXX MO: how to represent "ENOSYS"?
167 2 ▶ $lock->{type}==$fcntl->{F_UNLCK} ? undef : $lock;
Branch: 1 branch
BranchTrueFalseTotal
$lock->{'type'} == $fcntl->{'F_UNLCK'} ? : 1 1 2
168 }
169  
170  
171  
172 sub getfd_owner($%)
173 0 ▶{ my ($file, %args) = @_;
Subroutine getfd_owner: not called CC=8 SCAR=42.8
Pod documented
174 0 ▶ my $fd = ref $file ? fileno($file) : $file;
Branch: 1 branch
BranchTrueFalseTotal
ref $file ? : 0 0 0
175  
176 0 my ($type, $pid) = _own_ex $fd, $fcntl->{F_GETOWN_EX}, UNUSED, UNUSED;
177 0 ▶ unless(defined $type && $!==ENOSYS)
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $type and $! == 38) 0 0 0
Condition0%0/3
defined $type and $! == 38
!ll&&!rl&&r
000
MC/DC0%0/2
defined $type and $! == 38
defined $type $! == 38
Truth table0%0/3
A and B
A= defined $typeB= $! == 38
ABresult
0X0
100
111
178 0 { $pid = _fcntl $fd, $fcntl->{F_GETOWN}, UNUSED;
179 0 ▶ if($pid < 0)
Branch: 1 branch
BranchTrueFalseTotal
if ($pid < 0) { } 0 0 0
180 0 { $pid = -$pid;
181 0 ▶ $type = $fcntl->{F_OWNER_PGRP} // 2;
Condition0%0/2
$fcntl->{"F_OWNER_PGRP"} // 2
l!l
00
MC/DC0%0/1
$fcntl->{"F_OWNER_PGRP"} // 2
$fcntl->{"F_OWNER_PGRP"}
Truth table0%0/2
A
A= $fcntl->{"F_OWNER_PGRP"}
Aresult
11
00
182 }
183 else
184 0 ▶ { $type = $fcntl->{F_OWNER_PID} // 1;
Condition0%0/2
$fcntl->{"F_OWNER_PID"} // 1
l!l
00
MC/DC0%0/1
$fcntl->{"F_OWNER_PID"} // 1
$fcntl->{"F_OWNER_PID"}
Truth table0%0/2
A
A= $fcntl->{"F_OWNER_PID"}
Aresult
11
00
185 }
186 }
187  
188 0 ▶ wantarray ? ($type, $pid) : $pid;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
189 }
190  
191  
192  
193 sub setfd_owner($$%)
194 0 ▶{ my ($file, $pid, %args) = @_;
Subroutine setfd_owner: not called CC=11 SCAR=48.8
Pod documented
195 0 ▶ my $fd = ref $file ? fileno($file) : $file;
Branch: 1 branch
BranchTrueFalseTotal
ref $file ? : 0 0 0
196  
197 my $type = $args{type}
198 0 ▶ || ($pid < 0 ? ($fcntl->{F_OWNER_PGRP}//2) : ($fcntl->{F_OWNER_PID}//1));
Branch: 1 branch
BranchTrueFalseTotal
$pid < 0 ? : 0 0 0
Condition0%0/7
$args{'type'} || ($pid < 0 ? $fcntl->{'F_OWNER_PGRP'} // 2 : $fcntl->{'F_OWNER_PID'} // 1)
l!l&&r!l&&!r
000
$fcntl->{"F_OWNER_PGRP"} // 2
l!l
00
$fcntl->{"F_OWNER_PID"} // 1
l!l
00
MC/DC0%0/2
$args{'type'} || ($pid < 0 ? $fcntl->{'F_OWNER_PGRP'} // 2 : $fcntl->{'F_OWNER_PID'} // 1)
$args{'type'} ($pid < 0 ? $fcntl->{'F_OWNER_PGRP'} // 2 : $fcntl->{'F_OWNER_PID'} // 1)
MC/DC0%0/1
$fcntl->{"F_OWNER_PGRP"} // 2
$fcntl->{"F_OWNER_PGRP"}
MC/DC0%0/1
$fcntl->{"F_OWNER_PID"} // 1
$fcntl->{"F_OWNER_PID"}
Truth table0%0/3
A || B
A= $args{'type'}B= ($pid < 0 ? $fcntl->{'F_OWNER_PGRP'} // 2 : $fcntl->{'F_OWNER_PID'} // 1)
ABresult
1X1
011
000
Truth table0%0/2
A
A= $fcntl->{"F_OWNER_PGRP"}
Aresult
11
00
Truth table0%0/2
A
A= $fcntl->{"F_OWNER_PID"}
Aresult
11
00
199  
200 0 ▶ $pid = -$pid if $pid < 0;
Branch: 1 branch
BranchTrueFalseTotal
if $pid < 0 0 0 0
201  
202 0 my ($t, $p) = _own_ex $fd, $fcntl->{F_SETOWN_EX}, $pid, $type;
203 0 ▶ unless($t && $!==ENOSYS)
Branch: 1 branch
BranchTrueFalseTotal
unless ($t and $! == 38) 0 0 0
Condition0%0/3
$t and $! == 38
!ll&&!rl&&r
000
MC/DC0%0/2
$t and $! == 38
$t $! == 38
Truth table0%0/3
A and B
A= $tB= $! == 38
ABresult
0X0
100
111
204 0 ▶ { my $sig_pid = $type==($fcntl->{F_OWNER_PGRP}//2) ? -$pid : $pid;
Branch: 1 branch
BranchTrueFalseTotal
$type == ($fcntl->{'F_OWNER_PGRP'} // 2) ? : 0 0 0
Condition0%0/2
$fcntl->{"F_OWNER_PGRP"} // 2
l!l
00
MC/DC0%0/1
$fcntl->{"F_OWNER_PGRP"} // 2
$fcntl->{"F_OWNER_PGRP"}
Truth table0%0/2
A
A= $fcntl->{"F_OWNER_PGRP"}
Aresult
11
00
205 0 ($t, $p) = _fcntl $fd, $fcntl->{F_SETOWN}, $pid;
206 }
207  
208 0 defined $t;
209 }
210  
211  
212 sub setfd_signal($$)
213 0 ▶{ my ($file, $signal) = @_;
Subroutine setfd_signal: not called CC=2 SCAR=17.9
Pod documented
214 0 ▶ my $fd = ref $file ? fileno($file) : $file;
Branch: 1 branch
BranchTrueFalseTotal
ref $file ? : 0 0 0
215 0 _fcntl $fd, $fcntl->{F_SETSIG}, $signal;
216 }
217  
218  
219  
220 sub getfd_signal($)
221 0 ▶{ my $file = shift;
Subroutine getfd_signal: not called CC=2 SCAR=17.9
Pod documented
222 0 ▶ my $fd = ref $file ? fileno($file) : $file;
Branch: 1 branch
BranchTrueFalseTotal
ref $file ? : 0 0 0
223 0 _fcntl $fd, $fcntl->{F_SETSIG}, UNUSED;
224 }
225  
226  
227  
228 sub setfd_lease($$)
229 0 ▶{ my ($file, $flags) = @_;
Subroutine setfd_lease: not called CC=2 SCAR=17.9
Pod documented
230 0 ▶ my $fd = ref $file ? fileno($file) : $file;
Branch: 1 branch
BranchTrueFalseTotal
ref $file ? : 0 0 0
231 0 _fcntl $fd, $fcntl->{F_SETLEASE}, $flags;
232 }
233  
234  
235  
236 sub getfd_lease($)
237 0 ▶{ my $file = shift;
Subroutine getfd_lease: not called CC=2 SCAR=17.9
Pod documented
238 0 ▶ my $fd = ref $file ? fileno($file) : $file;
Branch: 1 branch
BranchTrueFalseTotal
ref $file ? : 0 0 0
239 0 _fcntl $fd, $fcntl->{F_GETLEASE}, UNUSED;
240 }
241  
242  
243  
244 sub setfd_notify($$)
245 0 ▶{ my ($dir, $flags) = @_;
Subroutine setfd_notify: not called CC=2 SCAR=17.9
Pod documented
246 0 ▶ my $fd = ref $dir ? fileno($dir) : $dir;
Branch: 1 branch
BranchTrueFalseTotal
ref $dir ? : 0 0 0
247 0 _fcntl $fd, $fcntl->{F_NOTIFY}, $flags;
248 }
249  
250  
251  
252 sub setfd_pipe_size($$)
253 0 ▶{ my ($file, $size) = @_;
Subroutine setfd_pipe_size: not called CC=2 SCAR=17.9
Pod documented
254 0 ▶ my $fd = ref $file ? fileno($file) : $file;
Branch: 1 branch
BranchTrueFalseTotal
ref $file ? : 0 0 0
255 0 _fcntl $fd, $fcntl->{F_SETPIPE_SZ}, $size;
256 }
257  
258  
259  
260 sub getfd_pipe_size($)
261 0 ▶{ my $file = shift;
Subroutine getfd_pipe_size: not called CC=2 SCAR=17.9
Pod documented
262 0 ▶ my $fd = ref $file ? fileno($file) : $file;
Branch: 1 branch
BranchTrueFalseTotal
ref $file ? : 0 0 0
263 0 _fcntl $fd, $fcntl->{F_GETPIPE_SZ}, UNUSED;
264 }
265  
266 #-----------------
267  
268  
269 sub _create_constant($)
270 86 ▶{ my ($class, $name) = @_;
Subroutine _create_constant: called CC=1 SCAR=0.2
271 86 my $val = $fcntl->{$name};
272 0 ▶ sub() {$val};
Subroutine __ANON__: not called CC=1 SCAR=1.2
273 }
274  
275 6 1;
« manuals.PL ↑ Summary blib/lib/POSIX/1003/Module.pm »