From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by sourceware.org (Postfix) with ESMTP id 1FF153858C27 for ; Mon, 16 Nov 2020 15:14:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 1FF153858C27 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-593-IV-hnqE8PzSM2Drzrw7UQA-1; Mon, 16 Nov 2020 10:14:02 -0500 X-MC-Unique: IV-hnqE8PzSM2Drzrw7UQA-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 9BE3B873115; Mon, 16 Nov 2020 15:14:01 +0000 (UTC) Received: from calimero.vinschen.de (ovpn-115-81.ams2.redhat.com [10.36.115.81]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 6C0FB196FD; Mon, 16 Nov 2020 15:14:01 +0000 (UTC) Received: by calimero.vinschen.de (Postfix, from userid 500) id E9B0DA80940; Mon, 16 Nov 2020 16:13:59 +0100 (CET) Date: Mon, 16 Nov 2020 16:13:59 +0100 From: Corinna Vinschen To: "Earle F. Philhower, III" Cc: newlib@sourceware.org Subject: Re: [PATCH] Add support for TZ names with <> in tzset Message-ID: <20201116151359.GD41926@calimero.vinschen.de> Reply-To: newlib@sourceware.org Mail-Followup-To: "Earle F. Philhower, III" , newlib@sourceware.org References: <080401d6bada$6c52f060$44f8d120$.ref@yahoo.com> <080401d6bada$6c52f060$44f8d120$@yahoo.com> MIME-Version: 1.0 In-Reply-To: <080401d6bada$6c52f060$44f8d120$@yahoo.com> X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=utf-8 Content-Disposition: inline X-Spam-Status: No, score=-13.0 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: newlib@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Newlib mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 16 Nov 2020 15:14:07 -0000 Hi Earle, On Nov 14 15:03, Earle F. Philhower, III via Newlib wrote: > Howdy all, > > Attached is a patch which extends the tzset() function to support a format > for "unnamed" TZ environment timezones which use "<+/-nn>" as the timezone > name instead of an alphabetic name. These are supported in glibc and are > present in several major TZ databases that we use on the ESP8266 Arduino > core. For example, > > > #define TZ_Africa_Casablanca "<+01>-1" > > The existing tzset sscanf format string breaks at the first "+", assuming > it's the > beginning of the offset. This patch special-cases names beginning with "<" > to > circumvent the issue. > > Signed-off-by: Earle F. Philhower, III Basically this looks ok. I have two nits, though. - Now that the scanning got more complicated than a single sscanf call, this crys out for a helper function doing the actual scanning for both, std and dst strings. This could be an inline function which is only inlined #if !defined(PREFER_SIZE_OVER_SPEED) && !defined(__OPTIMIZE_SIZE__) - The strcat call seems a bit heavy. What about sth like this instead: __tzname_ptr[n - 1] = '>'; __tzname_ptr[n] = '\0'; Thanks, Corinna > --- > newlib/libc/time/tzset_r.c | 46 ++++++++++++++++++++++++++++++-------- > 1 file changed, 37 insertions(+), 9 deletions(-) > > diff --git a/newlib/libc/time/tzset_r.c b/newlib/libc/time/tzset_r.c > index 9e0cf834b..5b8b692ee 100644 > --- a/newlib/libc/time/tzset_r.c > +++ b/newlib/libc/time/tzset_r.c > @@ -45,8 +45,19 @@ _tzset_unlocked_r (struct _reent *reent_ptr) > if (*tzenv == ':') > ++tzenv; > > - if (sscanf (tzenv, "%10[^0-9,+-]%n", __tzname_std, &n) <= 0) > - return; > + if (tzenv[0] == '<') > + { > + /* This is of the form "<[+-]nn>" so needs a different parsing */ > + if (sscanf (tzenv, "%9[^>]>%n", __tzname_std, &n) <= 0) > + return; > + /* Include the final > */ > + strcat (__tzname_std, ">"); > + } > + else > + { > + if (sscanf (tzenv, "%10[^0-9,+-]%n", __tzname_std, &n) <= 0) > + return; > + } > > tzenv += n; > > @@ -69,15 +80,32 @@ _tzset_unlocked_r (struct _reent *reent_ptr) > _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; > + if (tzenv[0] == '<') > + { > + /* This is of the form "<[+-]nn>" so needs a different parsing */ > + if (sscanf (tzenv, "%9[^>]>%n", __tzname_dst, &n) <= 0) > + { /* No dst */ > + _tzname[1] = _tzname[0]; > + _timezone = tz->__tzrule[0].offset; > + _daylight = 0; > + return; > + } > + /* Include the final > */ > + strcat (__tzname_dst, ">"); > + _tzname[1] = __tzname_dst; > } > 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; > + } > + else > + _tzname[1] = __tzname_dst; > + } > > tzenv += n; > > -- > 2.17.1 >