>From 04742d2e44109f4a01020c8d40bb8c1c860f6934 Mon Sep 17 00:00:00 2001
From: Paul Eggert <eggert@cs.ucla.edu>
Date: Sat, 11 Jan 2020 08:28:02 -0800
Subject: [PATCH] Fix leapseconds.awk portability bug

Reported by Deborah Goldsmith in:
https://mm.icann.org/pipermail/tz/2020-January/028781.html
* NEWS: Mention this.
* leapseconds.awk: Revert my 2019-07-29T04:13:23Z patch,
which was suggested by Brian Inglis here:
https://mm.icann.org/pipermail/tz/2019-July/028386.html
as RS = "\r?\n" is a GNU extension to POSIX.
---
 NEWS            | 3 +++
 leapseconds.awk | 6 +++---
 2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/NEWS b/NEWS
index ccc3dde..961aa08 100644
--- a/NEWS
+++ b/NEWS
@@ -21,6 +21,9 @@ Unreleased, experimental changes
     The configuration macro ALTZONE now has the same values with the
     same meaning as HAVE_TZNAME and USG_COMPAT.
 
+    The code's defense against CRLF in leap-seconds.list is now
+    portable to POSIX awk.  (Problem reported by Deborah Goldsmith.)
+
   Changes to commentary
 
     The Îles-de-la-Madeleine and the Listuguj reserve are noted as
diff --git a/leapseconds.awk b/leapseconds.awk
index 1fe5012..74bcda0 100755
--- a/leapseconds.awk
+++ b/leapseconds.awk
@@ -68,12 +68,12 @@ BEGIN {
   monthabbr[11] = "Nov"
   monthabbr[12] = "Dec"
 
-  # Strip trailing CR, in case the input has CRLF form a la NIST.
-  RS = "\r?\n"
-
   sstamp_init()
 }
 
+# In case the input has CRLF form a la NIST.
+{ sub(/\r$/, "") }
+
 /^#[ \t]*[Uu]pdated through/ || /^#[ \t]*[Ff]ile expires on/ {
     last_lines = last_lines $0 "\n"
 }
-- 
2.17.1

