# Copyright (C) 2001-2020 Yves Renard
#
# This file is a part of GetFEM
#
# GetFEM  is  free software;  you  can  redistribute  it  and/or modify it
# under  the  terms  of the  GNU  Lesser General Public License as published
# by  the  Free Software Foundation;  either version 3 of the License,  or
# (at your option) any later version.
# This program  is  distributed  in  the  hope  that it will be useful,  but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or  FITNESS  FOR  A PARTICULAR PURPOSE.  See the GNU Lesser General Public
# License for more details.
# You  should  have received a copy of the GNU Lesser General Public License
# along  with  this program;  if not, write to the Free Software Foundation,
# Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301, USA.

# -*- perl -*-
eval 'exec perl -S $0 "$@"'
  if 0;
# Create a temporary file with a unique name.
# if the environement variable TMPDIR exists it creates the temporary inside.

if ($ARGV[0] eq "") { $prefix = "_tempfile"; } else { $prefix = $ARGV[0]; }
$count = int(1000 * rand);
if ($ENV{TMPDIR} eq "") { $tmpdir = "/tmp"; } else { $tmpdir = $ENV{TMPDIR} }
if (substr($tmpdir, length($tmpdir)-1, 1) eq "/")
  { $tmpdir = substr($tmpdir, 0, length($tmpdir)-1); }
do { $name = $tmpdir."/".$prefix."\_$count"; ++$count; } while (-f $name);
`touch $name`; print $name;
