+sub write_to_file ($$) {
+ my ($file, $contents) = @_;
+ my $new = "$file.new";
+ open my $fh, ">", $new or sysfail "couldn't open `$new' for writing: $!";
+ print $fh $contents;
+ $fh->flush && !$fh->error && close $fh
+ or sysfail "failed to write to `$new': $!";
+ rename $new, $file or sysfail "failed to rename `$new' to `$file': $!";
+}
+