From f038801aea0ff24cf86511fa6679d7dcb859cd8d Mon Sep 17 00:00:00 2001 From: Nicholas Clark Date: Sun, 23 Jan 2011 10:07:52 +0000 Subject: In regen/*.pl, refactor the repeated code for close and rename if different. Pass the final file name as an optional second argument of safer_open() and store it with the file handle. Add a function close_and_rename() which closes the file handle, then retrieves the final name, and renames the temporary file if the two differ. --- regen/reentr.pl | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'regen/reentr.pl') diff --git a/regen/reentr.pl b/regen/reentr.pl index 963dd96e00..0045b1896d 100644 --- a/regen/reentr.pl +++ b/regen/reentr.pl @@ -51,7 +51,7 @@ my %map = ( # Example #3: S_CBI means type func_r(const char*, char*, int) -my $h = safer_open("reentr.h-new"); +my $h = safer_open('reentr.h-new', 'reentr.h'); select $h; print read_only_top(lang => 'C', by => 'regen/reentr.pl', from => 'data in regen/reentr.pl', @@ -786,12 +786,11 @@ typedef struct { /* ex: set ro: */ EOF -safer_close($h); -rename_if_different('reentr.h-new', 'reentr.h'); +close_and_rename($h); # Prepare to write the reentr.c. -my $c = safer_open("reentr.c-new"); +my $c = safer_open('reentr.c-new', 'reentr.c'); select $c; my $top = read_only_top(lang => 'C', by => 'regen/reentr.pl', from => 'data in regen/reentr.pl', @@ -1082,8 +1081,7 @@ Perl_reentrant_retry(const char *f, ...) /* ex: set ro: */ EOF -safer_close($c); -rename_if_different('reentr.c-new', 'reentr.c'); +close_and_rename($c); __DATA__ asctime S |time |const struct tm|B_SB|B_SBI|I_SB|I_SBI -- cgit v1.2.1