summaryrefslogtreecommitdiff
path: root/gnu
diff options
context:
space:
mode:
authorPhilip Guenthe <guenther@cvs.openbsd.org>2012-07-10 23:17:44 +0000
committerPhilip Guenthe <guenther@cvs.openbsd.org>2012-07-10 23:17:44 +0000
commit191d5963c899294598e421fab9182a6da4f16ee0 (patch)
treeec68b5ca3a47f0dcad44f9d83473868d9bca20ef /gnu
parent3bf481531b839d4c0f30afbf11cc1c1c131bcf21 (diff)
In a scalar context, mkstemp should return just the file handle
"sure" espie@
Diffstat (limited to 'gnu')
-rw-r--r--gnu/usr.bin/perl/cpan/OpenBSD-MkTemp/MkTemp.xs3
-rw-r--r--gnu/usr.bin/perl/cpan/OpenBSD-MkTemp/lib/OpenBSD/MkTemp.pm41
-rw-r--r--gnu/usr.bin/perl/cpan/OpenBSD-MkTemp/t/OpenBSD-MkTemp.t11
3 files changed, 42 insertions, 13 deletions
diff --git a/gnu/usr.bin/perl/cpan/OpenBSD-MkTemp/MkTemp.xs b/gnu/usr.bin/perl/cpan/OpenBSD-MkTemp/MkTemp.xs
index f1ea59cd51d..d817339bd4f 100644
--- a/gnu/usr.bin/perl/cpan/OpenBSD-MkTemp/MkTemp.xs
+++ b/gnu/usr.bin/perl/cpan/OpenBSD-MkTemp/MkTemp.xs
@@ -57,7 +57,8 @@ mkstemps(SV *template, ...)
mPUSHs(sv_bless(newRV((SV*)gv),
gv_stashpv("OpenBSD::MkTemp",1)));
SvREFCNT_dec(gv);
- PUSHs(path);
+ if (GIMME_V == G_ARRAY)
+ PUSHs(path);
} else {
close(fd);
unlink(SvPV_nolen(path));
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 cbde1ad1ee0..4048c958bd7 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
@@ -21,6 +21,7 @@ sub mkstemp($)
1;
__END__
+
=head1 NAME
OpenBSD::MkTemp - Perl access to mkstemps() and mkdtemp()
@@ -39,24 +40,44 @@ OpenBSD::MkTemp - Perl access to mkstemps() and mkdtemp()
=head1 DESCRIPTION
-This module provides routines for creating files and directories with
-guaranteed unique names, using the C mkstemps() and mkdtemp() routines.
+This module provides routines for creating files and directories
+with guaranteed unique names, using the C C<mkstemps()> and
+C<mkdtemp()> routines.
+On the perl-side, they are intended to behave the same as the
+functions provided by L<File::Temp>.
+
+For all these functions, the template provided follows the rules
+of the system's C<mkstemps()> and C<mkdtemp()> functions.
+The template may be any file name with some number of Xs appended
+to it, for example C</tmp/temp.XXXXXXXX>.
+The trailing Xs are replaced with a unique digit and letter combination.
+
+C<mkstemp()> takes a template and creates a new, unique file.
+In a list context, it returns a two items: a normal perl IO handle
+open to the new file for both read and write, and the generated
+filename.
+In a scalar context it just returns the IO handle.
+
+C<mkstemps()> takes the template and a suffix to append to the
+filename. For example, the call C<mkstemps("/tmp/temp.XXXXXXXXXX",
+".c")> might create the file C</tmp/temp.SO4csi32GM.c>.
+It returns the filename and/or filename just like C<mkstemp()>
+
+C<mkdtemp()> simply takes the template and returns the path of the
+newly created directory.
-mkstemp() and mkstemps() must be called with a template argument
-that is writable, so that they can update it with the path of the
-generated file.
-They return normal perl IO handles.
+Note that the files and directories created by these functions are
+I<not> automatically removed.
-mkdtemp() simply takes the template and returns the path of the
-newly created directory.
+On failure, all of these functions call die.
=head2 EXPORT
- $fh = mkstemp($template)
+ ($fh, $filename) = mkstemp($template)
=head2 Exportable functions
- $fh = mkstemps($template, $suffix_len)
+ ($fh, $filename) = mkstemps($template, $suffix)
$dir = mkdtemp($template);
=head1 SEE ALSO
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 8bea96d33b9..f99802b3609 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
@@ -38,7 +38,7 @@ my $template = $base . "X" x 10;
my($fh1, $file1) = mkstemp($template);
like($file1, qr/^\Q$base\E[a-zA-Z0-9]{10}$/, "mkstemp output format");
-ok(-f $file1, "mkstemp created filed");
+ok(-f $file1, "mkstemp created file");
my @stat = stat(_);
cmp_ok($stat[2] & 07777, '==', 0600, "mkstemp file mode");
@@ -46,10 +46,17 @@ my @fstat = stat($fh1);
is_deeply(\@stat, \@fstat, "file name matches the handle");
+# Verify scalar return case
+my $fh = mkstemp($template);
+ok(-f $fh, "mkstemp created file");
+my @stat = stat(_);
+cmp_ok($stat[2] & 07777, '==', 0600, "mkstemp file mode");
+
+
my($fh2, $file2) = OpenBSD::MkTemp::mkstemps($template, ".foo");
like($file2, qr/^\Q$base\E[a-zA-Z0-9]{10}\.foo$/, "mkstemps output format");
-ok(-f $file2, "mkstemps created filed");
+ok(-f $file2, "mkstemps created file");
@stat = stat(_);
cmp_ok($stat[2] & 07777, '==', 0600, "mkstemps file mode");