blib/lib/POSIX/1003/Fcntl.pm

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