cpan::OpenBSD-MkTemp::lib::OpenBSD::MkTemp(3p)

NAME
OpenBSD::MkTemp - Perl access to mkstemps() and mkdtemp()

SYNOPSIS
  use OpenBSD::MkTemp;

  my($fh, $file) = mkstemp("/tmp/fooXXXXXXXXXX");

  use OpenBSD::MkTemp qw(mkdtemp mkstemps);

  my $dir_name = mkdtemp("/tmp/dirXXXXXXXXXX");
  my ($fh, $file) = mkstemps("/tmp/fileXXXXXXXXXX", ".tmp");

DESCRIPTION
This module provides routines for creating files and directories with guaranteed unique names, using the C "mkstemps()" and "mkdtemp()" routines. On the perl-side, they are intended to behave the same as the functions provided by File::Temp.

For all these functions, the template provided follows the rules of the system's "mkstemps()" and "mkdtemp()" functions. The template may be any file name with some number of Xs appended to it, for example "/tmp/temp.XXXXXXXX". The trailing Xs are replaced with a unique digit and letter combination.

"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.

"mkstemps()" takes the template and a suffix to append to the filename. For example, the call "mkstemps("/tmp/temp.XXXXXXXXXX", ".c")" might create the file "/tmp/temp.SO4csi32GM.c". It returns the filename and/or filename just like "mkstemp()"

"mkdtemp()" simply takes the template and returns the path of the newly created directory.

Note that the files and directories created by these functions are not automatically removed.

On failure, all of these functions call die.

  EXPORT
  ($fh, $filename) = mkstemp($template)

  Exportable functions
  ($fh, $filename) = mkstemps($template, $suffix)
  $dir = mkdtemp($template);

SEE ALSO
mkstemp(3)

AUTHOR
Philip Guenther, <guenther@openbsd.org>

COPYRIGHT AND LICENSE
Copyright (C) 2010,2012 by Philip Guenther

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.12.2 or, at your option, any later version of Perl 5 you may have available.