regen_lib.pl 1010 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. #!/usr/bin/perl -w
  2. use strict;
  3. use vars qw($Is_W32 $Is_OS2 $Is_Cygwin $Is_NetWare $Needs_Write);
  4. use Config; # Remember, this is running using an existing perl
  5. # Common functions needed by the regen scripts
  6. $Is_W32 = $^O eq 'MSWin32';
  7. $Is_OS2 = $^O eq 'os2';
  8. $Is_Cygwin = $^O eq 'cygwin';
  9. $Is_NetWare = $Config{osname} eq 'NetWare';
  10. if ($Is_NetWare) {
  11. $Is_W32 = 0;
  12. }
  13. $Needs_Write = $Is_OS2 || $Is_W32 || $Is_Cygwin || $Is_NetWare;
  14. sub safer_unlink {
  15. my @names = @_;
  16. my $cnt = 0;
  17. my $name;
  18. foreach $name (@names) {
  19. next unless -e $name;
  20. chmod 0777, $name if $Needs_Write;
  21. ( CORE::unlink($name) and ++$cnt
  22. or warn "Couldn't unlink $name: $!\n" );
  23. }
  24. return $cnt;
  25. }
  26. sub safer_rename_silent {
  27. my ($from, $to) = @_;
  28. # Some dosish systems can't rename over an existing file:
  29. safer_unlink $to;
  30. chmod 0600, $from if $Needs_Write;
  31. rename $from, $to;
  32. }
  33. sub safer_rename {
  34. my ($from, $to) = @_;
  35. safer_rename_silent($from, $to) or die "renaming $from to $to: $!";
  36. }
  37. 1;