| 1 | # Copyrights 2012 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.00. | ||||||||||||||||||||||||||||
| 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::Util; | ||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use vars '$VERSION'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 2 | $VERSION = '0.10'; | |||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 2 | ▶ | use base 'Exporter'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | 2 | ▶ | use POSIX::1003::Pathconf qw/_PC_REC_INCR_XFER_SIZE/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 2 | ▶ | use POSIX::1003::FdIO qw/writefd readfd BUFSIZ SSIZE_MAX/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 2 | my @fdio = qw/readfd_all writefd_all/; | |||||||||||||||||||||||||||
| 18 | 2 | my @functions = (@fdio); | |||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | # need to extract the POSIX::1003 exporter | ||||||||||||||||||||||||||||
| 21 | 2 | our @EXPORT = @functions; | |||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 2 | our %EXPORT_TAGS = | |||||||||||||||||||||||||||
| 24 | ( functions => \@functions | ||||||||||||||||||||||||||||
| 25 | , fdio => \@fdio | ||||||||||||||||||||||||||||
| 26 | ); | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | sub writefd_all($$;$) | ||||||||||||||||||||||||||||
| 30 | 0 | ▶ | { my ($to, $data, $do_close) = @_; | ||||||||||||||||||||||||||
|
Subroutine
writefd_all: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||
| 31 | 0 | my $size = length $data; | |||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 0 | ▶ | while(my $l = length $data) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 34 | 0 | { my $written = writefd $to, $data, $l; | |||||||||||||||||||||||||||
| 35 | 0 | ▶ | defined $written or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 0 | ▶ | last if $l eq $written; # normal case | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 38 | 0 | substr($data, 0, $written) = ''; | |||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 0 | ▶ | $do_close && !defined closefd($to) ? undef : $size; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$do_close and not defined closefd($to)
MC/DC0%0/2
$do_close and not defined closefd($to)
$do_close
not defined closefd($to)
Truth table0%0/3
A and not(B)
A= $do_closeB= not defined closefd($to)
| |||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | sub readfd_all($;$$) | ||||||||||||||||||||||||||||
| 46 | 1 | ▶ | { my ($in, $size, $do_close) = @_; | ||||||||||||||||||||||||||
|
Subroutine
readfd_all: called CC=10 SCAR=25.4
Pod
documented
| |||||||||||||||||||||||||||||
| 47 | 1 | ▶ | defined $size or $size = SSIZE_MAX; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 48 | 1 | my ($data, $buf) = ('', ''); | |||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 1 | ▶ | my $block = _PC_REC_INCR_XFER_SIZE($in) || BUFSIZ || 4096; | ||||||||||||||||||||||||||
|
Condition50%2/4
&_PC_REC_INCR_XFER_SIZE($in) || 8192 || 4096
&_PC_REC_INCR_XFER_SIZE($in) or 8192
MC/DC0%0/1
&_PC_REC_INCR_XFER_SIZE($in) || 8192 || 4096
&_PC_REC_INCR_XFER_SIZE($in)
Truth table50%1/2
A
A= &_PC_REC_INCR_XFER_SIZE($in)
| |||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | # we should probably align the $in-fd onto a block size in the | ||||||||||||||||||||||||||||
| 53 | # first read for optimal performance under all cirmstances... | ||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||
| 55 | 1 | my $bytes; | |||||||||||||||||||||||||||
| 56 | 1 | ▶ | while($bytes = readfd $in, $buf, ($block < $size ? $block : $size)) | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 57 | 2 | ▶ | { last if $bytes==0; # readfd will return "0 but true" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | 1 | $data .= $buf; | |||||||||||||||||||||||||||
| 59 | 1 | $size -= $bytes; | |||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||
| 61 | 1 | ▶ | defined $bytes or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 1 | ▶ | $do_close && !defined closefd($in) ? undef : $data; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$do_close and not defined closefd($in)
MC/DC0%0/2
$do_close and not defined closefd($in)
$do_close
not defined closefd($in)
Truth table33%1/3
A and not(B)
A= $do_closeB= not defined closefd($in)
| |||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 2 | 1; | |||||||||||||||||||||||||||