1package OpenBSD::MkTemp; 2 3use 5.012002; 4use strict; 5use warnings; 6 7use Exporter 'import'; 8 9our @EXPORT_OK = qw( mkstemps mkstemp mkdtemp ); 10our @EXPORT = qw( mkstemp mkdtemp ); 11our $VERSION = '0.02'; 12 13require XSLoader; 14XSLoader::load('OpenBSD::MkTemp', $VERSION); 15 16sub mkstemp($) 17{ 18 my $template = shift; 19 my $fh = mkstemps_real($template, 0) || return; 20 return wantarray() ? ($fh, $template) : $fh; 21} 22 23sub mkstemps($$) 24{ 25 my($template, $suffix) = @_; 26 $template .= $suffix; 27 my $fh = mkstemps_real($template, length($suffix)) || return; 28 return wantarray() ? ($fh, $template) : $fh; 29} 30 31 321; 33__END__ 34=head1 NAME 35 36OpenBSD::MkTemp - Perl access to mkstemps() and mkdtemp() 37 38=head1 SYNOPSIS 39 40 use OpenBSD::MkTemp; 41 42 my($fh, $file) = mkstemp("/tmp/fooXXXXXXXXXX"); 43 44 use OpenBSD::MkTemp qw(mkdtemp mkstemps); 45 46 my $dir_name = mkdtemp("/tmp/dirXXXXXXXXXX"); 47 my ($fh, $file) = mkstemps("/tmp/fileXXXXXXXXXX", ".tmp"); 48 49 50=head1 DESCRIPTION 51 52This module provides routines for creating files and directories with 53guaranteed unique names, using the C mkstemps() and mkdtemp() routines. 54 55mkstemp() and mkstemps() must be called with a template argument 56that is writable, so that they can update it with the path of the 57generated file. 58They return normal perl IO handles. 59 60mkdtemp() simply takes the template and returns the path of the 61newly created directory. 62 63=head2 EXPORT 64 65 $fh = mkstemp($template) 66 67=head2 Exportable functions 68 69 $fh = mkstemps($template, $suffix_len) 70 $dir = mkdtemp($template); 71 72=head1 SEE ALSO 73 74mkstemp(3) 75 76=head1 AUTHOR 77 78Philip Guenther, E<lt>guenther@openbsd.orgE<gt> 79 80=head1 COPYRIGHT AND LICENSE 81 82Copyright (C) 2010 by Philip Guenther 83 84This library is free software; you can redistribute it and/or modify 85it under the same terms as Perl itself, either Perl version 5.12.2 or, 86at your option, any later version of Perl 5 you may have available. 87 88 89=cut 90