From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2134) id 12D9D3858D28; Fri, 8 Apr 2022 19:11:13 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 12D9D3858D28 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Jeff Johnston To: newlib-cvs@sourceware.org Subject: [newlib-cygwin] Add angle TZ angle bracket support to tzset_r X-Act-Checkin: newlib-cygwin X-Git-Author: Jeff Johnston X-Git-Refname: refs/heads/master X-Git-Oldrev: 2c157e7e23074a690494771a96a18033842e75be X-Git-Newrev: 539ac66ffa868762fbe43dd2e9b40d1a5407b53d Message-Id: <20220408191113.12D9D3858D28@sourceware.org> Date: Fri, 8 Apr 2022 19:11:13 +0000 (GMT) X-BeenThere: newlib-cvs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Newlib GIT logs List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 08 Apr 2022 19:11:13 -0000 https://sourceware.org/git/gitweb.cgi?p=3Dnewlib-cygwin.git;h=3D539ac66ffa8= 68762fbe43dd2e9b40d1a5407b53d commit 539ac66ffa868762fbe43dd2e9b40d1a5407b53d Author: Jeff Johnston Date: Fri Apr 8 15:06:37 2022 -0400 Add angle TZ angle bracket support to tzset_r =20 - from Brian Inglis =20 - add support to _tzset_unlocked_r() to support quoting std and dst names with angle brackets <> as per Posix - modify documentation of tzset.c Diff: --- newlib/libc/time/tzset.c | 110 ++++++++++++++++++++++++++++++++---------= ---- newlib/libc/time/tzset_r.c | 65 ++++++++++++++++++++++----- 2 files changed, 132 insertions(+), 43 deletions(-) diff --git a/newlib/libc/time/tzset.c b/newlib/libc/time/tzset.c index 3b4c01c66..77accbfb0 100644 --- a/newlib/libc/time/tzset.c +++ b/newlib/libc/time/tzset.c @@ -1,6 +1,6 @@ /* FUNCTION -<>---set timezone characteristics from TZ environment variable +<>---set timezone characteristics from <[TZ]> environment variable =20 INDEX tzset @@ -13,36 +13,84 @@ SYNOPSIS void _tzset_r (struct _reent *<[reent_ptr]>); =20 DESCRIPTION -<> examines the TZ environment variable and sets up the three -external variables: <<_timezone>>, <<_daylight>>, and <>. The -value of <<_timezone>> shall be the offset from the current time zone -to GMT. The value of <<_daylight>> shall be 0 if there is no daylight -savings time for the current time zone, otherwise it will be non-zero. -The <> array has two entries: the first is the name of the -standard time zone, the second is the name of the daylight-savings time -zone. - -The TZ environment variable is expected to be in the following POSIX -format: - - stdoffset1[dst[offset2][,start[/time1],end[/time2]]] - -where: std is the name of the standard time-zone (minimum 3 chars) - offset1 is the value to add to local time to arrive at Universal ti= me - it has the form: hh[:mm[:ss]] - dst is the name of the alternate (daylight-savings) time-zone (min = 3 chars) - offset2 is the value to add to local time to arrive at Universal ti= me - it has the same format as the std offset - start is the day that the alternate time-zone starts - time1 is the optional time that the alternate time-zone starts - (this is in local time and defaults to 02:00:00 if not specified) - end is the day that the alternate time-zone ends - time2 is the time that the alternate time-zone ends - (it is in local time and defaults to 02:00:00 if not specified) - -Note that there is no white-space padding between fields. Also note that -if TZ is null, the default is Universal GMT which has no daylight-savings -time. If TZ is empty, the default EST5EDT is used. +<> examines the <[TZ]> environment variable and sets up the three +external variables: <<_timezone>>, <<_daylight>>, and <>. +The value of <<_timezone>> shall be the offset from the current time +to Universal Time. +The value of <<_daylight>> shall be 0 if there is no daylight savings +time for the current time zone, otherwise it will be non-zero. +The <> array has two entries: the first is the designation of the +standard time period, the second is the designation of the alternate time +period. + +The <[TZ]> environment variable is expected to be in the following POSIX +format (spaces inserted for clarity): + + <[std]> <[offset1]> [<[dst]> [<[offset2]>] [,<[start]> [/<[time1]>], <= [end]> [/<[time2]>]]] + +where: + +<[std]> is the designation for the standard time period (minimum 3, +maximum <> bytes) in one of two forms: + +*- quoted within angle bracket '<' '>' characters: portable numeric +sign or alphanumeric characters in the current locale; the +quoting characters are not included in the designation + +*- unquoted: portable alphabetic characters in the current locale + +<[offset1]> is the value to add to local standard time to get Universal Ti= me; +it has the format: + + [<[S]>]<[hh]>[:<[mm]>[:<[ss]>]] + + where: + + <[S]> is an optional numeric sign character; if negative '-', the + time zone is East of the International Reference + Meridian; else it is positive and West, and '+' may be used + + <[hh]> is the required numeric hour between 0 and 24 + + <[mm]> is the optional numeric minute between 0 and 59 + + <[ss]> is the optional numeric second between 0 and 59 + +<[dst]> is the designation of the alternate (daylight saving or +summer) time period, with the same limits and forms as +the standard time period designation + +<[offset2]> is the value to add to local alternate time to get +Universal Time; it has the same format as <[offset1]> + +<[start]> is the date in the year that alternate time starts; +the form may be one of: +(quotes "'" around characters below are used only to distinguish literals) + + <[n]> zero based Julian day (0-365), counting February 29 Leap days + + 'J'<[n]> one based Julian day (1-365), not counting February 29 Leap + days; in all years day 59 is February 28 and day 60 is March 1 + + 'M'<[m]>'.'<[w]>'.'<[d]> + month <[m]> (1-12) week <[w]> (1-5) day <[d]> (0-6) where week 1 is + the first week in month <[m]> with day <[d]>; week 5 is the last + week in the month; day 0 is Sunday + +<[time1]> is the optional local time that alternate time starts, in +the same format as <[offset1]> without any sign, and defaults +to 02:00:00 + +<[end]> is the date in the year that alternate time ends, in the same +forms as <[start]> + +<[time2]> is the optional local time that alternate time ends, in +the same format as <[offset1]> without any sign, and +defaults to 02:00:00 + +Note that there is no white-space padding between fields. Also note that +if <[TZ]> is null, the default is Universal Time which has no daylight sav= ing +time. If <[TZ]> is empty, the default EST5EDT is used. =20 The function <<_tzset_r>> is identical to <> only it is reentrant and is used for applications that use multiple threads. diff --git a/newlib/libc/time/tzset_r.c b/newlib/libc/time/tzset_r.c index 9e0cf834b..9cb30b188 100644 --- a/newlib/libc/time/tzset_r.c +++ b/newlib/libc/time/tzset_r.c @@ -9,8 +9,11 @@ =20 #define sscanf siscanf /* avoid to pull in FP functions. */ =20 -static char __tzname_std[11]; -static char __tzname_dst[11]; +#define TZNAME_MIN 3 /* POSIX min TZ abbr size local def */ +#define TZNAME_MAX 10 /* POSIX max TZ abbr size local def */ + +static char __tzname_std[TZNAME_MAX + 1]; +static char __tzname_dst[TZNAME_MAX + 1]; static char *prev_tzenv =3D NULL; =20 void @@ -45,8 +48,25 @@ _tzset_unlocked_r (struct _reent *reent_ptr) if (*tzenv =3D=3D ':') ++tzenv; =20 =20 - if (sscanf (tzenv, "%10[^0-9,+-]%n", __tzname_std, &n) <=3D 0) - return; + /* allow POSIX angle bracket < > quoted signed alphanumeric tz abbr e.g.= */ + if (*tzenv =3D=3D '<') + { + ++tzenv; + + /* quit if no items, too few or too many chars, or no close quote '>= ' */ + if (sscanf (tzenv, "%10[-+0-9A-Za-z]%n", __tzname_std, &n) <=3D 0 + || n < TZNAME_MIN || TZNAME_MAX < n || '>' !=3D tzenv[n]) + return; + + ++tzenv; /* bump for close quote '>' */ + } + else + { + /* allow POSIX unquoted alphabetic tz abbr e.g. MESZ */ + if (sscanf (tzenv, "%10[A-Za-z]%n", __tzname_std, &n) <=3D 0 + || n < TZNAME_MIN || TZNAME_MAX < n) + return; + } =20 tzenv +=3D n; =20 @@ -68,17 +88,38 @@ _tzset_unlocked_r (struct _reent *reent_ptr) tz->__tzrule[0].offset =3D sign * (ss + SECSPERMIN * mm + SECSPERHOUR * = hh); _tzname[0] =3D __tzname_std; tzenv +=3D n; - =20 - if (sscanf (tzenv, "%10[^0-9,+-]%n", __tzname_dst, &n) <=3D 0) - { /* No dst */ - _tzname[1] =3D _tzname[0]; - _timezone =3D tz->__tzrule[0].offset; - _daylight =3D 0; - return; + + /* allow POSIX angle bracket < > quoted signed alphanumeric tz abbr e.g.= */ + if (*tzenv =3D=3D '<') + { + ++tzenv; + + /* quit if no items, too few or too many chars, or no close quote '>= ' */ + if (sscanf (tzenv, "%10[-+0-9A-Za-z]%n", __tzname_dst, &n) <=3D 0 + || n < TZNAME_MIN || TZNAME_MAX < n || '>' !=3D tzenv[n]) + { /* No dst */ + _tzname[1] =3D _tzname[0]; + _timezone =3D tz->__tzrule[0].offset; + _daylight =3D 0; + return; + } + + ++tzenv; /* bump for close quote '>' */ } else - _tzname[1] =3D __tzname_dst; + { + /* allow POSIX unquoted alphabetic tz abbr e.g. MESZ */ + if (sscanf (tzenv, "%10[A-Za-z]%n", __tzname_dst, &n) <=3D 0 + || n < TZNAME_MIN || TZNAME_MAX < n) + { /* No dst */ + _tzname[1] =3D _tzname[0]; + _timezone =3D tz->__tzrule[0].offset; + _daylight =3D 0; + return; + } + } =20 + _tzname[1] =3D __tzname_dst; tzenv +=3D n; =20 /* otherwise we have a dst name, look for the offset */