iets veiligere creatie van tijdelijke bestanden

This commit is contained in:
Ward Wouts 2013-01-23 10:57:51 +00:00
parent e8c8a098cd
commit df843589c0

View file

@ -3,7 +3,7 @@
# $Id$ # $Id$
# #
# Copyright (c) 2001 - 2007 Ward Wouts <ward@wouts.nl> # Copyright (c) 2001 - 2013 Ward Wouts <ward@wouts.nl>
# #
# Permission to use, copy, modify, and distribute this software for any # Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above # purpose with or without fee is hereby granted, provided that the above
@ -23,9 +23,10 @@
# Much easier than doing 6000 moves by hand # Much easier than doing 6000 moves by hand
# #
require File::Temp;
use File::Temp qw(tempfile);
use IO::File; use IO::File;
use File::Copy; use File::Copy;
use POSIX qw(tmpnam);
use Getopt::Long; use Getopt::Long;
use strict; use strict;
use warnings; use warnings;
@ -77,8 +78,8 @@ sub edit($) {
sub open_temp { sub open_temp {
my $target; my $target;
my $target_name; my $target_name;
do { $target_name = tmpnam() } ($target, $target_name) = tempfile( TEMPLATE => 'MVWXXXXXXX', SUFFIX => '.mvwrap');
until $target = IO::File->new($target_name, O_RDWR|O_CREAT|O_EXCL); # Volgende regel werkt niet...
END { if ($opt_e) { unlink($target_name) or die("Couldn't unlink $target_name: $!");} } END { if ($opt_e) { unlink($target_name) or die("Couldn't unlink $target_name: $!");} }
foreach (@source) { foreach (@source) {
print $target "$_\n"; print $target "$_\n";