File: TmpFile.pm

package info (click to toggle)
debconf 1.5.11etch2
  • links: PTS
  • area: main
  • in suites: etch
  • size: 3,364 kB
  • ctags: 714
  • sloc: perl: 8,347; sh: 286; makefile: 174; python: 117
file content (68 lines) | stat: -rw-r--r-- 898 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/perl

=head1 NAME

Debconf::TmpFile - temporary file creator

=cut

package Debconf::TmpFile;
use strict;
use IO::File;
use Fcntl;

=head1 DESCRIPTION

This module helps debconf make safe temporary files. At least, I think
they're safe, if /tmp is not on NFS.

=head1 METHODS

=over 4

=item open

Open a temporary file for writing. Returns an open file descriptor.
Optionally a file extension may be passed to it.

=cut

my $filename;

sub open {
	my $fh; # will be autovivified
	my $ext=shift || '';
	do { $filename=POSIX::tmpnam().$ext }
	until sysopen($fh, $filename, O_WRONLY|O_TRUNC|O_CREAT|O_EXCL, 0600);
	return $fh;
}

=item filename

Returns the name of the last opened temp file.

=cut

sub filename {
	return $filename;
}

=item cleanup

Unlinks the last opened tempfile.

=cut

sub cleanup {
	unlink $filename;
}

=back

=head1 AUTHOR

Joey Hess <joeyh@debian.org>

=cut

1