diff options
author | Eric Brine <ikegami@adaelis.com> | 2012-01-19 18:19:16 -0800 |
---|---|---|
committer | Father Chrysostomos <sprout@cpan.org> | 2012-01-19 22:38:36 -0800 |
commit | 84da5602d79c53542bee8b70ec90a6130da1175e (patch) | |
tree | 016c493131946d77c68a195415fe5fd205742465 /ext/PerlIO-scalar | |
parent | 8af88444359f912e4f4ff5726c58349bae916480 (diff) | |
download | perl-84da5602d79c53542bee8b70ec90a6130da1175e.tar.gz |
(PerlIO::)scalar.t: Add function for testing trailing null
Diffstat (limited to 'ext/PerlIO-scalar')
-rw-r--r-- | ext/PerlIO-scalar/t/scalar.t | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/ext/PerlIO-scalar/t/scalar.t b/ext/PerlIO-scalar/t/scalar.t index b59e3aa800..48883b6a78 100644 --- a/ext/PerlIO-scalar/t/scalar.t +++ b/ext/PerlIO-scalar/t/scalar.t @@ -317,3 +317,17 @@ EOF open my $fh, "<", \(my $f=*f); seek $fh, -2,2; pass 'seeking on a glob copy from the end'; } + +sub has_trailing_nul(\$) { + my ($ref) = @_; + my $sv = B::svref_2object($ref); + return undef if !$sv->isa('B::PV'); + + my $cur = $sv->CUR; + my $len = $sv->LEN; + return 0 if $cur >= $len; + + my $pv_addr = unpack 'J', pack 'P', $$ref; + my $trailing = unpack 'P', pack 'J', $pv_addr+$cur; + return $trailing eq "\0"; +} |