[nasm:nasm-2.15.xx] warnings.pl: again, don't update the timestamp unless we need to

nasm-bot for H. Peter Anvin (Intel) hpa at zytor.com
Fri Sep 11 18:15:12 PDT 2020


Commit-ID:  1a3bf7a3d714f4205c12db0b1cdfe5f2f36a6a3b
Gitweb:     http://repo.or.cz/w/nasm.git?a=commitdiff;h=1a3bf7a3d714f4205c12db0b1cdfe5f2f36a6a3b
Author:     H. Peter Anvin (Intel) <hpa at zytor.com>
AuthorDate: Fri, 11 Sep 2020 17:43:38 -0700
Committer:  H. Peter Anvin (Intel) <hpa at zytor.com>
CommitDate: Fri, 11 Sep 2020 17:43:38 -0700

warnings.pl: again, don't update the timestamp unless we need to

Don't update the timestamp unless we really have to do so.

Signed-off-by: H. Peter Anvin (Intel) <hpa at zytor.com>


---
 asm/warnings.pl | 27 +++++++++++++++------------
 1 file changed, 15 insertions(+), 12 deletions(-)

diff --git a/asm/warnings.pl b/asm/warnings.pl
index 6660d17a..11356860 100755
--- a/asm/warnings.pl
+++ b/asm/warnings.pl
@@ -279,17 +279,20 @@ if ($what eq 'c') {
 close($out);
 
 # Write data to file if and only if it has changed
-# Windows requires append mode here
-open($out, '+>>', $outfile)
-    or die "$0: cannot open output file $outfile: $!\n";
-my $datalen = length($outdata);
-my $oldlen = read($out, my $oldoutdata, $datalen+1);
-if (!defined($oldlen) || $oldlen != $datalen ||
-    !($oldoutdata eq $outdata)) {
-    # Data changed, must rewrite
-    truncate($out, 0);
-    seek($out, 0, SEEK_SET)
-	or die "$0: cannot rewind output file $outfile: $!\n";
-    print $out $outdata;
+# For some systems, even if we don't write, opening for append
+# apparently touches the timestamp, so we need to read and write
+# as separate operations.
+if (open(my $out, '<', $outfile)) {
+    my $datalen = length($outdata);
+    my $oldlen = read($out, my $oldoutdata, $datalen+1);
+    close($out);
+    exit 0 if (defined($oldlen) && $oldlen == $datalen &&
+	       ($oldoutdata eq $outdata));
 }
+
+# Data changed, must rewrite
+open(my $out, '>', $outfile)
+    or die "$0: cannot open output file $outfile: $!\n";
+
+print $out $outdata;
 close($out);


More information about the Nasm-commits mailing list