| 1 | # SMB-Perl library, Copyright (C) 2014 Mikhael Goikhman, migo@cpan.org | ||||||||||||||||||||
| 2 | # | ||||||||||||||||||||
| 3 | # This program is free software: you can redistribute it and/or modify | ||||||||||||||||||||
| 4 | # it under the terms of the GNU General Public License as published by | ||||||||||||||||||||
| 5 | # the Free Software Foundation, either version 3 of the License, or | ||||||||||||||||||||
| 6 | # (at your option) any later version. | ||||||||||||||||||||
| 7 | # | ||||||||||||||||||||
| 8 | # This program is distributed in the hope that it will be useful, | ||||||||||||||||||||
| 9 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||||||||||||||||||
| 10 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||||||||||||||||||
| 11 | # GNU General Public License for more details. | ||||||||||||||||||||
| 12 | # | ||||||||||||||||||||
| 13 | # You should have received a copy of the GNU General Public License | ||||||||||||||||||||
| 14 | # along with this program. If not, see <http://www.gnu.org/licenses/>. | ||||||||||||||||||||
| 15 | |||||||||||||||||||||
| 16 | package SMB::OpenFile; | ||||||||||||||||||||
| 17 | |||||||||||||||||||||
| 18 | 3 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 19 | 3 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 20 | |||||||||||||||||||||
| 21 | 3 | ▶ | use parent 'SMB'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 22 | |||||||||||||||||||||
| 23 | 3 | ▶ | use Fcntl 'SEEK_SET'; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 24 | 3 | ▶ | use SMB::File; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | sub new ($$$$%) { | ||||||||||||||||||||
| 27 | 17 | ▶ | my $class = shift; | ||||||||||||||||||
|
Subroutine
new: called CC=4 SCAR=14.3
Pod
documented
| |||||||||||||||||||||
| 28 | 17 | ▶ | my $file = shift || die "No file\n"; | ||||||||||||||||||
|
Condition50%1/2
shift() || die("No file\n")
MC/DC0%0/1
shift() || die("No file\n")
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||
| 29 | 17 | ▶ | my $handle = shift || 0; | ||||||||||||||||||
|
Condition50%1/2
shift() || 0
MC/DC0%0/1
shift() || 0
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||
| 30 | 17 | ▶ | my $action = shift || SMB::File::ACTION_NONE; | ||||||||||||||||||
|
Condition50%1/2
shift() || -1
MC/DC0%0/1
shift() || -1
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||
| 31 | 17 | my %options = @_; | |||||||||||||||||||
| 32 | |||||||||||||||||||||
| 33 | 17 | my $self = $class->SUPER::new( | |||||||||||||||||||
| 34 | file => $file, | ||||||||||||||||||||
| 35 | handle => $handle, | ||||||||||||||||||||
| 36 | action => $action, | ||||||||||||||||||||
| 37 | last_index => 0, | ||||||||||||||||||||
| 38 | %options, | ||||||||||||||||||||
| 39 | ); | ||||||||||||||||||||
| 40 | |||||||||||||||||||||
| 41 | 17 | return $self; | |||||||||||||||||||
| 42 | } | ||||||||||||||||||||
| 43 | |||||||||||||||||||||
| 44 | sub close ($) { | ||||||||||||||||||||
| 45 | 17 | ▶ | my $self = shift; | ||||||||||||||||||
|
Subroutine
close: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||
| 46 | |||||||||||||||||||||
| 47 | 17 | $self->file->delete_openfile($self); | |||||||||||||||||||
| 48 | } | ||||||||||||||||||||
| 49 | |||||||||||||||||||||
| 50 | sub read ($%) { | ||||||||||||||||||||
| 51 | 0 | ▶ | my $self = shift; | ||||||||||||||||||
|
Subroutine
read: not called CC=8 SCAR=42.8
Pod
undocumented
| |||||||||||||||||||||
| 52 | 0 | my %params = @_; # length offset minlen remain | |||||||||||||||||||
| 53 | |||||||||||||||||||||
| 54 | 0 | ▶ | my $fh = $self->{handle} or return; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 55 | 0 | ▶ | sysseek($fh, $params{offset} || 0, SEEK_SET) or return; | ||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$params{'offset'} || 0
MC/DC0%0/1
$params{'offset'} || 0
$params{'offset'}
Truth table0%0/2
A
A= $params{'offset'}
| |||||||||||||||||||||
| 56 | |||||||||||||||||||||
| 57 | 0 | ▶ | my $length = $params{length} // return; | ||||||||||||||||||
|
Condition0%0/2
$params{"length"} // (return)
MC/DC0%0/1
$params{"length"} // (return)
$params{"length"}
Truth table0%0/2
A
A= $params{"length"}
| |||||||||||||||||||||
| 58 | 0 | ▶ | my $minlen = $params{minlen} || 0; | ||||||||||||||||||
|
Condition0%0/2
$params{'minlen'} || 0
MC/DC0%0/1
$params{'minlen'} || 0
$params{'minlen'}
Truth table0%0/2
A
A= $params{'minlen'}
| |||||||||||||||||||||
| 59 | |||||||||||||||||||||
| 60 | 0 | my $buffer; | |||||||||||||||||||
| 61 | 0 | ▶ | sysread($fh, $buffer, $length) // return; | ||||||||||||||||||
|
Condition0%0/2
sysread($fh, $buffer, $length) // (return)
MC/DC0%0/1
sysread($fh, $buffer, $length) // (return)
sysread($fh, $buffer, $length)
Truth table0%0/2
A
A= sysread($fh, $buffer, $length)
| |||||||||||||||||||||
| 62 | 0 | ▶ | return unless length($buffer) < $minlen; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 63 | |||||||||||||||||||||
| 64 | 0 | return $buffer; | |||||||||||||||||||
| 65 | } | ||||||||||||||||||||
| 66 | |||||||||||||||||||||
| 67 | 3 | 1; | |||||||||||||||||||