From a5f03d96eee482cd84861fc8cefff9eb451c0cad Mon Sep 17 00:00:00 2001 From: xleroy Date: Sun, 29 Mar 2009 09:47:11 +0000 Subject: Cleaned up configure script. Distribution of CIL as an expanded source tree with changes applied (instead of original .tar.gz + patches to be applied at config time). git-svn-id: https://yquem.inria.fr/compcert/svn/compcert/trunk@1020 fca1b0fc-160b-0410-b1d3-a4f43f01ea2e --- cil/lib/TempFile.pm | 90 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 cil/lib/TempFile.pm (limited to 'cil/lib/TempFile.pm') diff --git a/cil/lib/TempFile.pm b/cil/lib/TempFile.pm new file mode 100644 index 00000000..608713cf --- /dev/null +++ b/cil/lib/TempFile.pm @@ -0,0 +1,90 @@ +package TempFile; +use OutputFile; +@ISA = (OutputFile); + +use strict; +use Carp; +use File::Temp qw(tempfile); + + +######################################################################## + + +sub new { + croak 'bad argument count' unless @_ == 3; + my ($proto, $basis, $suffix) = @_; + my $class = ref($proto) || $proto; + + my (undef, $filename) = tempfile('cil-XXXXXXXX', + DIR => File::Spec->tmpdir, + SUFFIX => ".$suffix", + UNLINK => 1); + + my $self = $class->SUPER::new($basis, $filename); + return $self; +} + + +######################################################################## + + +1; + +__END__ + + +=head1 Name + +TempFile - transitory compiler output files + +=head1 Synopsis + + use TempFile; + + my $cppOut = new TempFile ('code.c', 'i'); + system 'cpp', 'code.c', '-o', $cppOut->filename; + +=head2 Description + +C represents an intermediate output file generated by some +stage of a C-based compiler that should be removed after +compilation. It is a concrete subclass of L. +Use C when the user has asked not for intermediate files to +be retained. + +All C files are removed when the script terminates. This +cleanup happens for both normal exits as well as fatal errors. +However, the standard L does not +perform cleanups, and therefore should be avoided in scripts that use +C. + +=head2 Public Methods + +=over + +=item new + +C constructs a new C +instance. The new file name is constructed in some system-specific +temporary directory with a randomly generated file name that ends with +C<$suffix>. For example, + + new TempFile ('/foo/code.c', 'i') + +might yield a C with file name F. + +C<$basis> gives the basis file name for this instance. The file name +is not used directly, but is retained in case this instance is later +passed as the basis for some other C. See +L for more information on basis flattening. + +C<$suffix> should not include a leading dot; this will be added +automatically. + +=back + +=head1 See Also + +L, L. + +=cut -- cgit