| 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 | 8 | ▶ | use vars '$VERSION'; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 11 | 8 | $VERSION = '1.02'; | |||||||||||||||||
| 12 | |||||||||||||||||||
| 13 | 8 | ▶ | use base 'POSIX::1003::Module'; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 14 | |||||||||||||||||||
| 15 | 8 | ▶ | use warnings; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 16 | 8 | ▶ | use strict; | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 17 | |||||||||||||||||||
| 18 | # Blocks resp from unistd.h, limits.h, and stdio.h | ||||||||||||||||||
| 19 | 8 | my (@constants, @seek, @mode, @at); | |||||||||||||||||
| 20 | 8 | my @functions = qw/closefd creatfd dupfd dup2fd openfd pipefd | |||||||||||||||||
| 21 | readfd seekfd writefd tellfd truncfd fdopen/; | ||||||||||||||||||
| 22 | |||||||||||||||||||
| 23 | 8 | 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 | 8 | my $fdio; | |||||||||||||||||
| 33 | 8 | our (%fdio, %seek, %mode, %at); | |||||||||||||||||
| 34 | |||||||||||||||||||
| 35 | 8 | ▶ | BEGIN { | ||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||
| 36 | 8 | $fdio = fdio_table; | |||||||||||||||||
| 37 | 8 | push @constants, keys %$fdio; | |||||||||||||||||
| 38 | |||||||||||||||||||
| 39 | # initialize the :seek export tag | ||||||||||||||||||
| 40 | 8 | push @seek, grep /^SEEK_/, keys %$fdio; | |||||||||||||||||
| 41 | 8 | my %seek_subset; | |||||||||||||||||
| 42 | 8 | @seek_subset{@seek} = @{$fdio}{@seek}; | |||||||||||||||||
| 43 | 8 | tie %seek, 'POSIX::1003::ReadOnlyTable', \%seek_subset; | |||||||||||||||||
| 44 | |||||||||||||||||||
| 45 | # initialize the :mode export tag | ||||||||||||||||||
| 46 | 8 | push @mode, grep /^O_/, keys %$fdio; | |||||||||||||||||
| 47 | 8 | my %mode_subset; | |||||||||||||||||
| 48 | 8 | @mode_subset{@mode} = @{$fdio}{@mode}; | |||||||||||||||||
| 49 | 8 | tie %mode, 'POSIX::1003::ReadOnlyTable', \%mode_subset; | |||||||||||||||||
| 50 | |||||||||||||||||||
| 51 | # initialize the :at export tag | ||||||||||||||||||
| 52 | 8 | push @at, grep /^AT_/, keys %$fdio; | |||||||||||||||||
| 53 | 8 | my %at_subset; | |||||||||||||||||
| 54 | 8 | @at_subset{@at} = @{$fdio}{@at}; | |||||||||||||||||
| 55 | 8 | tie %at, 'POSIX::1003::ReadOnlyTable', \%at_subset; | |||||||||||||||||
| 56 | } | ||||||||||||||||||
| 57 | |||||||||||||||||||
| 58 | |||||||||||||||||||
| 59 | 5 | ▶ | sub seekfd($$$) { goto &POSIX::lseek } | ||||||||||||||||
|
Subroutine
seekfd: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||
| 60 | 4 | ▶ | sub openfd($$;$) { goto &POSIX::open } | ||||||||||||||||
|
Subroutine
openfd: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||
| 61 | 5 | ▶ | sub closefd($) { goto &POSIX::close } | ||||||||||||||||
|
Subroutine
closefd: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||
| 62 | 1 | ▶ | sub readfd($$;$) { push @_, SSIZE_MAX() if @_==2; goto &POSIX::read } | ||||||||||||||||
|
Subroutine
readfd: called CC=2 SCAR=7.2
Pod
documented
Branch: 1 branch
| |||||||||||||||||||
| 63 | 0 | ▶ | sub writefd($$;$) { push @_, length $_[1] if @_==2; goto &POSIX::write } | ||||||||||||||||
|
Subroutine
writefd: not called CC=2 SCAR=17.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||
| 64 | 0 | ▶ | sub pipefd() { goto &POSIX::pipe } | ||||||||||||||||
|
Subroutine
pipefd: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||
| 65 | 0 | ▶ | sub dupfd($) { goto &POSIX::dup } | ||||||||||||||||
|
Subroutine
dupfd: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||
| 66 | 0 | ▶ | sub dup2fd($$) { goto &POSIX::dup2 } | ||||||||||||||||
|
Subroutine
dup2fd: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||
| 67 | 0 | ▶ | sub statfd($) { goto &POSIX::fstat } | ||||||||||||||||
|
Subroutine
statfd: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||
| 68 | 0 | ▶ | sub creatfd($$) { openfd $_[0], O_WRONLY()|O_CREAT()|O_TRUNC(), $_[1] } | ||||||||||||||||
|
Subroutine
creatfd: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||
| 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 | ▶ | { my ($fd, $mode) = @_; | ||||||||||||||||
|
Subroutine
fdopen: called CC=6 SCAR=22.0
Pod
documented
| |||||||||||||||||||
| 76 | |||||||||||||||||||
| 77 | 1 | ▶ | $mode =~ m/^([rwa]\+?|\<|\>|\>>)$/ | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 78 | or die "illegal fdopen() mode '$mode'\n"; | ||||||||||||||||||
| 79 | |||||||||||||||||||
| 80 | 1 | ▶ | my $m = $1 eq 'r' ? '<' : $1 eq 'w' ? '>' : $1 eq 'a' ? '>>' : $1; | ||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||
| 81 | |||||||||||||||||||
| 82 | 1 | ▶ | die "fdopen() mode '$mode' (both read and write) is not supported\n" | ||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||
| 83 | if substr($m,-1) eq '+'; | ||||||||||||||||||
| 84 | |||||||||||||||||||
| 85 | 1 | open my($fh), "$m&=", $fd; | |||||||||||||||||
| 86 | 1 | $fh; | |||||||||||||||||
| 87 | } | ||||||||||||||||||
| 88 | |||||||||||||||||||
| 89 | |||||||||||||||||||
| 90 | #------------------ | ||||||||||||||||||
| 91 | |||||||||||||||||||
| 92 | 1 | ▶ | sub tellfd($) {seekfd $_[0], 0, SEEK_CUR() } | ||||||||||||||||
|
Subroutine
tellfd: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||
| 93 | 0 | ▶ | sub rewindfd() {seekfd $_[0], 0, SEEK_SET() } | ||||||||||||||||
|
Subroutine
rewindfd: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||
| 94 | |||||||||||||||||||
| 95 | |||||||||||||||||||
| 96 | sub _create_constant($) | ||||||||||||||||||
| 97 | 61 | ▶ | { my ($class, $name) = @_; | ||||||||||||||||
|
Subroutine
_create_constant: called CC=1 SCAR=0.2
| |||||||||||||||||||
| 98 | 61 | my $val = $fdio->{$name}; | |||||||||||||||||
| 99 | 0 | ▶ | sub() {$val}; | ||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||
| 100 | } | ||||||||||||||||||
| 101 | |||||||||||||||||||
| 102 | 8 | 1; | |||||||||||||||||