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::FdIO; |
10
|
6
|
|
|
6
|
|
216598
|
use vars '$VERSION'; |
|
6
|
|
|
|
|
40
|
|
|
6
|
|
|
|
|
342
|
|
11
|
|
|
|
|
|
|
$VERSION = '1.02'; |
12
|
|
|
|
|
|
|
|
13
|
6
|
|
|
6
|
|
32
|
use base 'POSIX::1003::Module'; |
|
6
|
|
|
|
|
10
|
|
|
6
|
|
|
|
|
1540
|
|
14
|
|
|
|
|
|
|
|
15
|
6
|
|
|
6
|
|
43
|
use warnings; |
|
6
|
|
|
|
|
9
|
|
|
6
|
|
|
|
|
164
|
|
16
|
6
|
|
|
6
|
|
30
|
use strict; |
|
6
|
|
|
|
|
7
|
|
|
6
|
|
|
|
|
2078
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
# Blocks resp from unistd.h, limits.h, and stdio.h |
19
|
|
|
|
|
|
|
my (@constants, @seek, @mode, @at); |
20
|
|
|
|
|
|
|
my @functions = qw/closefd creatfd dupfd dup2fd openfd pipefd |
21
|
|
|
|
|
|
|
readfd seekfd writefd tellfd truncfd fdopen/; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
our %EXPORT_TAGS = |
24
|
|
|
|
|
|
|
( constants => \@constants |
25
|
|
|
|
|
|
|
, functions => \@functions |
26
|
|
|
|
|
|
|
, seek => \@seek |
27
|
|
|
|
|
|
|
, mode => \@mode |
28
|
|
|
|
|
|
|
, at => \@at |
29
|
|
|
|
|
|
|
, tables => [ qw/%seek %mode %at/ ] |
30
|
|
|
|
|
|
|
); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
my $fdio; |
33
|
|
|
|
|
|
|
our (%fdio, %seek, %mode, %at); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
BEGIN { |
36
|
6
|
|
|
6
|
|
367
|
$fdio = fdio_table; |
37
|
6
|
|
|
|
|
96
|
push @constants, keys %$fdio; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
# initialize the :seek export tag |
40
|
6
|
|
|
|
|
102
|
push @seek, grep /^SEEK_/, keys %$fdio; |
41
|
6
|
|
|
|
|
19
|
my %seek_subset; |
42
|
6
|
|
|
|
|
11
|
@seek_subset{@seek} = @{$fdio}{@seek}; |
|
6
|
|
|
|
|
26
|
|
43
|
6
|
|
|
|
|
41
|
tie %seek, 'POSIX::1003::ReadOnlyTable', \%seek_subset; |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# initialize the :mode export tag |
46
|
6
|
|
|
|
|
119
|
push @mode, grep /^O_/, keys %$fdio; |
47
|
6
|
|
|
|
|
19
|
my %mode_subset; |
48
|
6
|
|
|
|
|
8
|
@mode_subset{@mode} = @{$fdio}{@mode}; |
|
6
|
|
|
|
|
40
|
|
49
|
6
|
|
|
|
|
18
|
tie %mode, 'POSIX::1003::ReadOnlyTable', \%mode_subset; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
# initialize the :at export tag |
52
|
6
|
|
|
|
|
120
|
push @at, grep /^AT_/, keys %$fdio; |
53
|
6
|
|
|
|
|
23
|
my %at_subset; |
54
|
6
|
|
|
|
|
61
|
@at_subset{@at} = @{$fdio}{@at}; |
|
6
|
|
|
|
|
40
|
|
55
|
6
|
|
|
|
|
26
|
tie %at, 'POSIX::1003::ReadOnlyTable', \%at_subset; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
|
59
|
5
|
|
|
5
|
1
|
1834
|
sub seekfd($$$) { goto &POSIX::lseek } |
60
|
4
|
|
|
4
|
1
|
2398
|
sub openfd($$;$) { goto &POSIX::open } |
61
|
5
|
|
|
5
|
1
|
3078
|
sub closefd($) { goto &POSIX::close } |
62
|
1
|
50
|
|
1
|
1
|
4
|
sub readfd($$;$) { push @_, SSIZE_MAX() if @_==2; goto &POSIX::read } |
|
1
|
|
|
|
|
15
|
|
63
|
0
|
0
|
|
0
|
1
|
0
|
sub writefd($$;$) { push @_, length $_[1] if @_==2; goto &POSIX::write } |
|
0
|
|
|
|
|
0
|
|
64
|
0
|
|
|
0
|
1
|
0
|
sub pipefd() { goto &POSIX::pipe } |
65
|
0
|
|
|
0
|
1
|
0
|
sub dupfd($) { goto &POSIX::dup } |
66
|
0
|
|
|
0
|
1
|
0
|
sub dup2fd($$) { goto &POSIX::dup2 } |
67
|
0
|
|
|
0
|
1
|
0
|
sub statfd($) { goto &POSIX::fstat } |
68
|
0
|
|
|
0
|
1
|
0
|
sub creatfd($$) { openfd $_[0], O_WRONLY()|O_CREAT()|O_TRUNC(), $_[1] } |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
# This is implemented via CORE::open, because we need an Perl FH, not a |
72
|
|
|
|
|
|
|
# FILE *. |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub fdopen($$) |
75
|
1
|
|
|
1
|
1
|
3
|
{ my ($fd, $mode) = @_; |
76
|
|
|
|
|
|
|
|
77
|
1
|
50
|
|
|
|
9
|
$mode =~ m/^([rwa]\+?|\<|\>|\>>)$/ |
78
|
|
|
|
|
|
|
or die "illegal fdopen() mode '$mode'\n"; |
79
|
|
|
|
|
|
|
|
80
|
1
|
0
|
|
|
|
6
|
my $m = $1 eq 'r' ? '<' : $1 eq 'w' ? '>' : $1 eq 'a' ? '>>' : $1; |
|
|
0
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
81
|
|
|
|
|
|
|
|
82
|
1
|
50
|
|
|
|
4
|
die "fdopen() mode '$mode' (both read and write) is not supported\n" |
83
|
|
|
|
|
|
|
if substr($m,-1) eq '+'; |
84
|
|
|
|
|
|
|
|
85
|
1
|
|
|
|
|
30
|
open my($fh), "$m&=", $fd; |
86
|
1
|
|
|
|
|
6
|
$fh; |
87
|
|
|
|
|
|
|
} |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
#------------------ |
91
|
|
|
|
|
|
|
|
92
|
1
|
|
|
1
|
1
|
7
|
sub tellfd($) {seekfd $_[0], 0, SEEK_CUR() } |
93
|
0
|
|
|
0
|
1
|
0
|
sub rewindfd() {seekfd $_[0], 0, SEEK_SET() } |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub _create_constant($) |
97
|
57
|
|
|
57
|
|
86
|
{ my ($class, $name) = @_; |
98
|
57
|
|
|
|
|
69
|
my $val = $fdio->{$name}; |
99
|
57
|
|
|
0
|
|
352
|
sub() {$val}; |
|
0
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
1; |