From: Brian Inglis <Brian.Inglis@SystematicSW.ab.ca>
To: newlib@sourceware.org
Subject: [PATCH] newlib/libc/time/tzset_r.c(_tzset_unlocked_r): add POSIX <> quoted abbrs
Date: Tue, 15 Feb 2022 14:57:01 -0700 [thread overview]
Message-ID: <20220215215701.40283-1-Brian.Inglis@SystematicSW.ab.ca> (raw)
[-- 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 */
next reply other threads:[~2022-02-15 21:57 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-15 21:57 Brian Inglis [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220215215701.40283-1-Brian.Inglis@SystematicSW.ab.ca \
--to=brian.inglis@systematicsw.ab.ca \
--cc=newlib@sourceware.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).