summaryrefslogtreecommitdiff
path: root/gnu/usr.bin/perl/regen_lib.pl
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>2003-12-03 02:44:40 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>2003-12-03 02:44:40 +0000
commit0121b80e4f69c2ad9631e8d20b5c91f3b2a40434 (patch)
tree49a8ade446c1b6277c06982988700467e1be139c /gnu/usr.bin/perl/regen_lib.pl
parent184128d6fb928711cdef9d8e6980dc6601fb1f87 (diff)
perl 5.8.2 from CPAN
Diffstat (limited to 'gnu/usr.bin/perl/regen_lib.pl')
-rw-r--r--gnu/usr.bin/perl/regen_lib.pl45
1 files changed, 45 insertions, 0 deletions
diff --git a/gnu/usr.bin/perl/regen_lib.pl b/gnu/usr.bin/perl/regen_lib.pl
new file mode 100644
index 00000000000..1c830a2cdcf
--- /dev/null
+++ b/gnu/usr.bin/perl/regen_lib.pl
@@ -0,0 +1,45 @@
+#!/usr/bin/perl -w
+use strict;
+use vars qw($Is_W32 $Is_OS2 $Is_Cygwin $Is_NetWare $Needs_Write);
+use Config; # Remember, this is running using an existing perl
+
+# Common functions needed by the regen scripts
+
+$Is_W32 = $^O eq 'MSWin32';
+$Is_OS2 = $^O eq 'os2';
+$Is_Cygwin = $^O eq 'cygwin';
+$Is_NetWare = $Config{osname} eq 'NetWare';
+if ($Is_NetWare) {
+ $Is_W32 = 0;
+}
+
+$Needs_Write = $Is_OS2 || $Is_W32 || $Is_Cygwin || $Is_NetWare;
+
+sub safer_unlink {
+ my @names = @_;
+ my $cnt = 0;
+
+ my $name;
+ foreach $name (@names) {
+ next unless -e $name;
+ chmod 0777, $name if $Needs_Write;
+ ( CORE::unlink($name) and ++$cnt
+ or warn "Couldn't unlink $name: $!\n" );
+ }
+ return $cnt;
+}
+
+sub safer_rename_silent {
+ my ($from, $to) = @_;
+
+ # Some dosish systems can't rename over an existing file:
+ safer_unlink $to;
+ chmod 0600, $from if $Needs_Write;
+ rename $from, $to;
+}
+
+sub safer_rename {
+ my ($from, $to) = @_;
+ safer_rename_silent($from, $to) or die "renaming $from to $to: $!";
+}
+1;