diff options
author | Andrew Fresh <afresh1@cvs.openbsd.org> | 2016-05-08 03:53:29 +0000 |
---|---|---|
committer | Andrew Fresh <afresh1@cvs.openbsd.org> | 2016-05-08 03:53:29 +0000 |
commit | 5531f9bc63845773f6c8109aee278fb78ced9581 (patch) | |
tree | 93de8565c5e4a156da0e7d8c618cb595cc413a5a | |
parent | fb11b217ffc6c7228336b94c073d06cb13e35c82 (diff) |
Correct return value of OpenBSD::MkTemp in scalar context
From Francesco Toscan < f.toscan AT hotmail DOT it >
ok guenther@
-rw-r--r-- | gnu/usr.bin/perl/cpan/OpenBSD-MkTemp/lib/OpenBSD/MkTemp.pm | 8 | ||||
-rw-r--r-- | gnu/usr.bin/perl/cpan/OpenBSD-MkTemp/t/OpenBSD-MkTemp.t | 12 |
2 files changed, 16 insertions, 4 deletions
diff --git a/gnu/usr.bin/perl/cpan/OpenBSD-MkTemp/lib/OpenBSD/MkTemp.pm b/gnu/usr.bin/perl/cpan/OpenBSD-MkTemp/lib/OpenBSD/MkTemp.pm index d5c8efbe208..20131be15d3 100644 --- a/gnu/usr.bin/perl/cpan/OpenBSD-MkTemp/lib/OpenBSD/MkTemp.pm +++ b/gnu/usr.bin/perl/cpan/OpenBSD-MkTemp/lib/OpenBSD/MkTemp.pm @@ -16,16 +16,16 @@ XSLoader::load('OpenBSD::MkTemp', $VERSION); sub mkstemp($) { my $template = shift; - my $fh = mkstemps_real($template, 0); - return $fh && ($fh, $template) + my $fh = mkstemps_real($template, 0) || return; + return wantarray() ? ($fh, $template) : $fh; } sub mkstemps($$) { my($template, $suffix) = @_; $template .= $suffix; - my $fh = mkstemps_real($template, length($suffix)); - return $fh && ($fh, $template) + my $fh = mkstemps_real($template, length($suffix)) || return; + return wantarray() ? ($fh, $template) : $fh; } diff --git a/gnu/usr.bin/perl/cpan/OpenBSD-MkTemp/t/OpenBSD-MkTemp.t b/gnu/usr.bin/perl/cpan/OpenBSD-MkTemp/t/OpenBSD-MkTemp.t index c4fa9c35239..143d80d2cec 100644 --- a/gnu/usr.bin/perl/cpan/OpenBSD-MkTemp/t/OpenBSD-MkTemp.t +++ b/gnu/usr.bin/perl/cpan/OpenBSD-MkTemp/t/OpenBSD-MkTemp.t @@ -10,6 +10,7 @@ use warnings; use Test::More; use Errno; +use Scalar::Util qw( openhandle ); BEGIN { use_ok('OpenBSD::MkTemp') }; ######################### @@ -62,6 +63,17 @@ undef $fh2; open(F, ">$file2") || die "$0: unable to open $file2: $!"; cmp_ok(fileno(F), '==', $fileno, "mkstemp file handle ref counting"); +subtest "mkstemp in scalar context" => sub { + plan tests => 2; + ok my $fh = OpenBSD::MkTemp::mkstemp($template); + is openhandle($fh), $fh, "mkstemp returns a filehandle in scalar mode"; +}; + +subtest "mkstemps in scalar context" => sub { + plan tests => 2; + ok my $fh = OpenBSD::MkTemp::mkstemps($template, ".foo"); + is openhandle($fh), $fh, "mkstemps returns a filehandle in scalar mode"; +}; # # How about some failures? |