$F = $filename;
}
else {
- safer_unlink $filename if $filename ne '/dev/null';
- open F, ">$filename" or die "Can't open $filename: $!";
+ # safer_unlink $filename if $filename ne '/dev/null';
+ open F, ">$filename-new" or die "Can't open $filename: $!";
binmode F;
$F = \*F;
}
print $F $trailer if $trailer;
unless (ref $filename) {
close $F or die "Error closing $filename: $!";
+ safer_rename("$filename-new", $filename);
}
}
return hide("PL_$pre$sym", "PL_$sym");
}
-safer_unlink 'embed.h';
-open(EM, '> embed.h') or die "Can't create embed.h: $!\n";
+open(EM, '> embed.h-new') or die "Can't create embed.h: $!\n";
binmode EM;
print EM do_not_edit ("embed.h"), <<'END';
END
close(EM) or die "Error closing EM: $!";
+safer_rename('embed.h-new', 'embed.h');
-safer_unlink 'embedvar.h';
-open(EM, '> embedvar.h')
+open(EM, '> embedvar.h-new')
or die "Can't create embedvar.h: $!\n";
binmode EM;
END
close(EM) or die "Error closing EM: $!";
+safer_rename('embedvar.h-new', 'embedvar.h');
-safer_unlink 'perlapi.h';
-safer_unlink 'perlapi.c';
-open(CAPI, '> perlapi.c') or die "Can't create perlapi.c: $!\n";
+open(CAPI, '> perlapi.c-new') or die "Can't create perlapi.c: $!\n";
binmode CAPI;
-open(CAPIH, '> perlapi.h') or die "Can't create perlapi.h: $!\n";
+open(CAPIH, '> perlapi.h-new') or die "Can't create perlapi.h: $!\n";
binmode CAPIH;
print CAPIH do_not_edit ("perlapi.h"), <<'EOT';
/* ex: set ro: */
EOT
close CAPIH or die "Error closing CAPIH: $!";
+safer_rename('perlapi.h-new', 'perlapi.h');
print CAPI do_not_edit ("perlapi.c"), <<'EOT';
EOT
close(CAPI) or die "Error closing CAPI: $!";
+safer_rename('perlapi.c-new', 'perlapi.c');
# functions that take va_list* for implementing vararg functions
# NOTE: makedef.pl must be updated if you add symbols to %vfuncs
use strict;
require 'regen_lib.pl';
-safer_unlink ("keywords.h");
-open(KW, ">keywords.h") || die "Can't create keywords.h: $!\n";
+
+open(KW, ">keywords.h-new") || die "Can't create keywords.h: $!\n";
binmode KW;
select KW;
close KW or die "Error closing keywords.h: $!";
+safer_rename("keywords.h-new", "keywords.h");
+
###########################################################################
sub tab {
my ($l, $t) = @_;
close OC or die "Error closing opcode.h: $!\n";
close ON or die "Error closing opnames.h: $!\n";
-foreach ('opcode.h', 'opnames.h') {
- safer_rename_silent $_, "$_-old";
-}
safer_rename $opcode_new, 'opcode.h';
safer_rename $opname_new, 'opnames.h';
close PP or die "Error closing pp_proto.h: $!\n";
close PPSYM or die "Error closing pp.sym: $!\n";
-foreach ('pp_proto.h', 'pp.sym') {
- safer_rename_silent $_, "$_-old";
-}
safer_rename $pp_proto_new, 'pp_proto.h';
safer_rename $pp_sym_new, 'pp.sym';
use strict;
use Getopt::Std;
my %opts;
-getopts('U', \%opts);
+getopts('Uv', \%opts);
my %map = (
V => "void",
# Example #3: S_CBI means type func_r(const char*, char*, int)
-safer_unlink 'reentr.h';
-die "reentr.h: $!" unless open(H, ">reentr.h");
+# safer_unlink 'reentr.h';
+die "reentr.pl: $!" unless open(H, ">reentr.h-new");
binmode H;
select H;
print <<EOF;
EOF
close(H);
+safer_rename('reentr.h-new', 'reentr.h');
# Prepare to write the reentr.c.
-safer_unlink 'reentr.c';
-die "reentr.c: $!" unless open(C, ">reentr.c");
+# safer_unlink 'reentr.c';
+die "reentr.c: $!" unless open(C, ">reentr.c-new");
binmode C;
select C;
print <<EOF;
/* ex: set ro: */
EOF
+close(C);
+safer_rename('reentr.c-new', 'reentr.c');
+
__DATA__
asctime S |time |const struct tm|B_SB|B_SBI|I_SB|I_SBI
crypt CC |crypt |struct crypt_data|B_CCS|B_CCD|D=CRYPTD*
require 'regen_lib.pl';
# keep warnings.pl in sync with the CPAN distribution by not requiring core
-# changes
-safer_unlink ("warnings.h", "lib/warnings.pm");
+# changes. Um, what ?
+# safer_unlink ("warnings.h", "lib/warnings.pm");
my %gen = (
'autodoc.pl' => [qw[pod/perlapi.pod pod/perlintern.pod]],
$Needs_Write = $Is_OS2 || $Is_W32 || $Is_Cygwin || $Is_NetWare;
+eval "use Digest::MD5 'md5'; 1;"
+ or warn "Digest::MD5 unavailable, doing unconditional regen\n";
+
+sub cksum {
+ my $pl = shift;
+ my ($buf, $cksum);
+ local *FH;
+ if (open(FH, $pl)) {
+ local $/;
+ $buf = <FH>;
+ $cksum = defined &md5 ? md5($buf) : 0;
+ close FH;
+ } else {
+ warn "$0: $pl: $!\n";
+ }
+ return $cksum;
+}
+
sub safer_unlink {
my @names = @_;
my $cnt = 0;
rename $from, $to;
}
+sub safer_rename_always {
+ my ($from, $to) = @_;
+ safer_rename_silent($from, $to) or die "renaming $from to $to: $!";
+}
+
sub safer_rename {
my ($from, $to) = @_;
+
+ my $fc = cksum($from);
+ my $tc = cksum($to);
+
+ if ($fc and $fc eq $tc) {
+ warn "no changes between '$from' & '$to'\n";
+ safer_unlink($from);
+ return;
+ }
+ warn "changed '$from' to '$to'\n";
safer_rename_silent($from, $to) or die "renaming $from to $to: $!";
}
1;
$VERSION = '1.02_02';
BEGIN {
- push @INC, './lib';
+ require 'regen_lib.pl';
+ push @INC, './lib';
}
use strict ;
exit ;
}
-unlink "warnings.h";
-unlink "lib/warnings.pm";
-open(WARN, ">warnings.h") || die "Can't create warnings.h: $!\n";
+open(WARN, ">warnings.h-new") || die "Can't create warnings.h: $!\n";
+open(PM, ">lib/warnings.pm-new") || die "Can't create lib/warnings.pm: $!\n";
binmode WARN;
-open(PM, ">lib/warnings.pm") || die "Can't create lib/warnings.pm: $!\n";
binmode PM;
print WARN <<'EOM' ;
EOM
close WARN ;
+safer_rename("warnings.h-new", "warnings.h");
while (<DATA>) {
last if /^KEYWORDS$/ ;
print PM "# ex: set ro:\n";
close PM ;
+safer_rename("lib/warnings.pm-new", "lib/warnings.pm");
__END__
# -*- buffer-read-only: t -*-