public inbox for newlib@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] newlib/libc/time/tzset_r.c(_tzset_unlocked_r): add POSIX <> quoted abbrs
@ 2022-02-15 21:57 Brian Inglis
  2022-02-15 22:04 ` [PATCH 0/1] " Brian Inglis
  0 siblings, 1 reply; 9+ messages in thread
From: Brian Inglis @ 2022-02-15 21:57 UTC (permalink / raw)
  To: newlib

[-- Attachment #1: Type: text/plain, Size: 128 bytes --]

---
 newlib/libc/time/tzset_r.c | 68 ++++++++++++++++++++++++++++++++------
 1 file changed, 58 insertions(+), 10 deletions(-)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: 0001-newlib-libc-time-tzset_r.c-_tzset_unlocked_r-add-POSIX-quoted-abbrs.patch --]
[-- Type: text/x-patch; name="0001-newlib-libc-time-tzset_r.c-_tzset_unlocked_r-add-POSIX-quoted-abbrs.patch", Size: 2342 bytes --]

diff --git a/newlib/libc/time/tzset_r.c b/newlib/libc/time/tzset_r.c
index 9e0cf834bd6b..5bf463ed3dd7 100644
--- a/newlib/libc/time/tzset_r.c
+++ b/newlib/libc/time/tzset_r.c
@@ -45,8 +45,30 @@ _tzset_unlocked_r (struct _reent *reent_ptr)
   if (*tzenv == ':')
     ++tzenv;  
 
-  if (sscanf (tzenv, "%10[^0-9,+-]%n", __tzname_std, &n) <= 0)
-    return;
+  /* allow POSIX angle bracket < > quoted tz abbr e.g. <+03> */
+  if (*tzenv == '<')
+    {
+      ++tzenv;
+
+      /* scan while dest space left, not EoS, not close quote */
+      for (n = 0;
+	     n < sizeof (__tzname_std) && tzenv[n] && '>' != tzenv[n];
+	       ++n)
+	{
+	  __tzname_std[n] = tzenv[n];
+	}
+
+      /* quit if no chars scanned, not close quote, or too many chars */
+      if (!n || '>' != tzenv[n] || sizeof (__tzname_std) <= n)
+	return;
+
+      __tzname_std[n] = '\0';
+    }
+  else
+    {
+      if (sscanf (tzenv, "%10[^0-9,+-]%n", __tzname_std, &n) <= 0)
+        return;
+    }
  
   tzenv += n;
 
@@ -68,17 +90,43 @@ _tzset_unlocked_r (struct _reent *reent_ptr)
   tz->__tzrule[0].offset = sign * (ss + SECSPERMIN * mm + SECSPERHOUR * hh);
   _tzname[0] = __tzname_std;
   tzenv += n;
-  
-  if (sscanf (tzenv, "%10[^0-9,+-]%n", __tzname_dst, &n) <= 0)
-    { /* No dst */
-      _tzname[1] = _tzname[0];
-      _timezone = tz->__tzrule[0].offset;
-      _daylight = 0;
-      return;
+
+  /* allow POSIX angle bracket < > quoted tz abbr e.g. <+03> */
+  if (*tzenv == '<')
+    {
+      ++tzenv;
+
+      /* scan while dest space left, not EoS, not close quote */
+      for (n = 0;
+	     n < sizeof (__tzname_dst) && tzenv[n] && '>' != tzenv[n];
+	       ++n)
+	{
+	  __tzname_dst[n] = tzenv[n];
+	}
+
+      /* quit if no chars scanned, not close quote, or too many chars */
+      if (!n || '>' != tzenv[n] || sizeof (__tzname_dst) <= n)
+	{ /* No dst */
+	  _tzname[1] = _tzname[0];
+	  _timezone = tz->__tzrule[0].offset;
+	  _daylight = 0;
+	  return;
+	}
+
+	__tzname_dst[n] = '\0';
     }
   else
-    _tzname[1] = __tzname_dst;
+    {
+      if (sscanf (tzenv, "%10[^0-9,+-]%n", __tzname_dst, &n) <= 0)
+	{ /* No dst */
+	  _tzname[1] = _tzname[0];
+	  _timezone = tz->__tzrule[0].offset;
+	  _daylight = 0;
+	  return;
+	}
+    }
 
+  _tzname[1] = __tzname_dst;
   tzenv += n;
 
   /* otherwise we have a dst name, look for the offset */

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2022-02-19  5:31 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-15 21:57 [PATCH] newlib/libc/time/tzset_r.c(_tzset_unlocked_r): add POSIX <> quoted abbrs Brian Inglis
2022-02-15 22:04 ` [PATCH 0/1] " Brian Inglis
2022-02-16  5:38   ` Brian Inglis
2022-02-16  8:55     ` Corinna Vinschen
2022-02-16 19:18       ` Brian Inglis
2022-02-17 12:11         ` Corinna Vinschen
2022-02-18  3:43           ` Brian Inglis
2022-02-18 14:16             ` Jon Turney
2022-02-19  5:31               ` Brian Inglis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).