line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
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
|
|
|
2
|
|
45815
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
67
|
|
6
|
2
|
|
|
2
|
|
10
|
use strict; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
84
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
package POSIX::Util; |
9
|
2
|
|
|
2
|
|
21
|
use vars '$VERSION'; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
99
|
|
10
|
|
|
|
|
|
|
$VERSION = '0.10'; |
11
|
|
|
|
|
|
|
|
12
|
2
|
|
|
2
|
|
11
|
use base 'Exporter'; |
|
2
|
|
|
|
|
2
|
|
|
2
|
|
|
|
|
184
|
|
13
|
|
|
|
|
|
|
|
14
|
2
|
|
|
2
|
|
1628
|
use POSIX::1003::Pathconf qw/_PC_REC_INCR_XFER_SIZE/; |
|
2
|
|
|
|
|
9311
|
|
|
2
|
|
|
|
|
22
|
|
15
|
2
|
|
|
2
|
|
1880
|
use POSIX::1003::FdIO qw/writefd readfd BUFSIZ SSIZE_MAX/; |
|
2
|
|
|
|
|
1665
|
|
|
2
|
|
|
|
|
19
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
my @fdio = qw/readfd_all writefd_all/; |
18
|
|
|
|
|
|
|
my @functions = (@fdio); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
# need to extract the POSIX::1003 exporter |
21
|
|
|
|
|
|
|
our @EXPORT = @functions; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
our %EXPORT_TAGS = |
24
|
|
|
|
|
|
|
( functions => \@functions |
25
|
|
|
|
|
|
|
, fdio => \@fdio |
26
|
|
|
|
|
|
|
); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub writefd_all($$;$) |
30
|
0
|
|
|
0
|
1
|
0
|
{ my ($to, $data, $do_close) = @_; |
31
|
0
|
|
|
|
|
0
|
my $size = length $data; |
32
|
|
|
|
|
|
|
|
33
|
0
|
|
|
|
|
0
|
while(my $l = length $data) |
34
|
0
|
|
|
|
|
0
|
{ my $written = writefd $to, $data, $l; |
35
|
0
|
0
|
|
|
|
0
|
defined $written or return; |
36
|
|
|
|
|
|
|
|
37
|
0
|
0
|
|
|
|
0
|
last if $l eq $written; # normal case |
38
|
0
|
|
|
|
|
0
|
substr($data, 0, $written) = ''; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
0
|
0
|
0
|
|
|
0
|
$do_close && !defined closefd($to) ? undef : $size; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub readfd_all($;$$) |
46
|
1
|
|
|
1
|
1
|
768
|
{ my ($in, $size, $do_close) = @_; |
47
|
1
|
50
|
|
|
|
6
|
defined $size or $size = SSIZE_MAX; |
48
|
1
|
|
|
|
|
2
|
my ($data, $buf) = ('', ''); |
49
|
|
|
|
|
|
|
|
50
|
1
|
|
50
|
|
|
6
|
my $block = _PC_REC_INCR_XFER_SIZE($in) || BUFSIZ || 4096; |
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
|
|
|
|
|
25
|
my $bytes; |
56
|
1
|
50
|
|
|
|
6
|
while($bytes = readfd $in, $buf, ($block < $size ? $block : $size)) |
57
|
2
|
100
|
|
|
|
44
|
{ last if $bytes==0; # readfd will return "0 but true" |
58
|
1
|
|
|
|
|
2
|
$data .= $buf; |
59
|
1
|
|
|
|
|
4
|
$size -= $bytes; |
60
|
|
|
|
|
|
|
} |
61
|
1
|
50
|
|
|
|
3
|
defined $bytes or return; |
62
|
|
|
|
|
|
|
|
63
|
1
|
50
|
33
|
|
|
6
|
$do_close && !defined closefd($in) ? undef : $data; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
1; |