From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from omta001.cacentral1.a.cloudfilter.net (omta001.cacentral1.a.cloudfilter.net [3.97.99.32]) by sourceware.org (Postfix) with ESMTPS id 467093858D20 for ; Mon, 28 Feb 2022 19:26:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 467093858D20 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=SystematicSw.ab.ca Authentication-Results: sourceware.org; spf=none smtp.mailfrom=systematicsw.ab.ca Received: from shw-obgw-4003a.ext.cloudfilter.net ([10.228.9.183]) by cmsmtp with ESMTP id Oj1Fn3Ykm43SgOleznRM8h; Mon, 28 Feb 2022 19:26:17 +0000 Received: from [10.0.0.5] ([184.64.124.72]) by cmsmtp with ESMTP id OleznvRglQV6mOlezn71Bm; Mon, 28 Feb 2022 19:26:17 +0000 X-Authority-Analysis: v=2.4 cv=PbTsOwtd c=1 sm=1 tr=0 ts=621d21d9 a=oHm12aVswOWz6TMtn9zYKg==:117 a=oHm12aVswOWz6TMtn9zYKg==:17 a=IkcTkHD0fZMA:10 a=TImcKGuyeGIbufSLrCcA:9 a=QEXdDO2ut3YA:10 Message-ID: <9925a077-b528-d1cc-71f5-e7ed86feedfe@SystematicSw.ab.ca> Date: Mon, 28 Feb 2022 12:26:16 -0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.6.1 Reply-To: newlib@sourceware.org Subject: Re: [PATCH 2/2] newlib/libc/time/tzset_r.c(_tzset_unlocked_r): POSIX angle bracket <> support Content-Language: en-CA To: newlib@sourceware.org References: <20220225163959.48753-1-Brian.Inglis@SystematicSW.ab.ca> <20220225163959.48753-3-Brian.Inglis@SystematicSW.ab.ca> From: Brian Inglis Organization: Systematic Software In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-CMAE-Envelope: MS4xfBWn+a5JVsAX3j8j3eifuaQJeoWGrhC35XoG7CL/+Ur5LaXiKmSB2TtY+uiB0zjAsMGbXhfVRp6al1//aZTft8d4XInvGkucCxczorsL/lGyXt7pK0mG /SLdQyzRlUKGvwyBVSwG+DnrRbKtL9fXRuQKWaj9UarQvS3jRoFQi/d+VHQ9Aux0jjWq7x5OuA1tJIE6HvYIlcC1QQpBgpEgUYo= X-Spam-Status: No, score=-1168.4 required=5.0 tests=BAYES_00, BODY_8BITS, GIT_PATCH_0, KAM_DMARC_STATUS, KAM_LAZY_DOMAIN_SECURITY, NICE_REPLY_A, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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, 28 Feb 2022 19:26:19 -0000 On 2022-02-28 11:55, Brian Inglis wrote: > On 2022-02-28 05:04, Corinna Vinschen wrote: >> Hi Brian, >> >> On Feb 25 09:39, Brian Inglis wrote: >>> >>> define POSIX specified minimum TZ abbr size 3 TZNAME_MIN >>> use limits.h TZNAME_MAX, _POSIX_TZNAME_MAX, unistd.h >>> sysconf(_SC_TZNAME_MAX) >>> issue error if no symbols defined (document fallback value in case >>> required) >>> allow POSIX angle bracket < > quoted signed alphanumeric tz abbr e.g. >>> >>> allow POSIX unquoted alphabetic tz abbr e.g. MESZ >>> apply same changes for DST tz abbr >>> --- >>>   newlib/libc/time/tzset_r.c | 74 ++++++++++++++++++++++++++++++++------ >>>   1 file changed, 64 insertions(+), 10 deletions(-) >>> >> >>> diff --git a/newlib/libc/time/tzset_r.c b/newlib/libc/time/tzset_r.c >>> index 9e0cf834bd6b..6a5fd578c0be 100644 >>> --- a/newlib/libc/time/tzset_r.c >>> +++ b/newlib/libc/time/tzset_r.c >>> @@ -1,14 +1,30 @@ >>>   #include <_ansi.h> >>> +#include     /* {,_POSIX_}TZNAME_MAX */ >>>   #include >>>   #include >>>   #include >>>   #include >>> +#include     /* sysconf(_SC_TZNAME_MAX) */ >>>   #include >>>   #include >>>   #include "local.h" >>>   #define sscanf siscanf    /* avoid to pull in FP functions. */ >>> +#define TZNAME_MIN    3    /* POSIX specified minimum TZ abbr size */ >> >> Are you sure? > > Minimum is historical. > >>> +/* TZNAME_MAX - POSIX specified maximum TZ abbr size */ >>> +/* define TZNAME_MAX if undefined and available */ >>> +#if    !defined(TZNAME_MAX) >>> +#if     defined(_POSIX_TZNAME_MAX) >>> +#define TZNAME_MAX    _POSIX_TZNAME_MAX    /* use POSIX value */ >>> +#elif     defined(_SC_TZNAME_MAX) >>> +#define TZNAME_MAX    sysconf(_SC_TZNAME_MAX)    /* use sysconf >>> value */ >> >> This is not a safe bet.  _SC_TZNAME_MAX is defined in unistd.h >> unconditionally, even for targets not providing sysconf().  And > > Why define indices if they are unusable on that platform? > >> given that _POSIX_TZNAME_MAX is only defined for RTEMS and Cygwin, >> this will run into problems on most other targets. >> >> Only Phoenix-RTOS, RISCV, RTEMS and Cygwin support sysconf, and none >> of them actually supports _SC_TZNAME_MAX as parameter.  And even Cygwin >> returns -1 and sets errno to EINVAL. >> >> Given you're checking _POSIX_TZNAME_MAX first, which is defined on >> Cygwin, the sysconf path will never be used there anyway.  But that's >> actually a minor point. >> >> The real problem is, you can't use sysconf(_SC_TZNAME_MAX) like this: >> - You don't know at compile time if the function is really supported. >> - You don't know if _SC_TZNAME_MAX returns a positive value or -1. > > The docs appeared unclear whether the index or return value could be -1. > POSIX sysconf(3p) man page says -1/EINVAL means invalid argument value > which should not apply if _SC_TZNAME_MAX is defined, otherwise -1/errno > is unchanged means no definite limit?! > I can just enclose it in HAVE_SYSCONF, else define a macro returning -1, >  and leave it at that for our purposes, while allowing for any platform > that decides to support it. Looks like I should define _SC_TZNAME_MAX == TZNAME_MAX and _SC_MONOTONIC_CLOCK == _POSIX_MONOTONIC_CLOCK in sysconf.cc? -- Take care. Thanks, Brian Inglis, Calgary, Alberta, Canada This email may be disturbing to some readers as it contains too much technical detail. Reader discretion is advised. [Data in binary units and prefixes, physical quantities in SI.]