Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nW0yJ-0007nu-40 for pgsql-hackers@arkaria.postgresql.org; Sun, 20 Mar 2022 19:12:11 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1nW0yH-00028n-0H for pgsql-hackers@arkaria.postgresql.org; Sun, 20 Mar 2022 19:12:09 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nW0yG-00028e-NC for pgsql-hackers@lists.postgresql.org; Sun, 20 Mar 2022 19:12:08 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nW0yA-0002xB-5w for pgsql-hackers@postgresql.org; Sun, 20 Mar 2022 19:12:07 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 22KJBsiO1565809; Sun, 20 Mar 2022 15:11:54 -0400 From: Tom Lane To: Robert Haas cc: Justin Pryzby , Dipesh Pandit , Andres Freund , Jeevan Ladhe , Alvaro Herrera , "Shinoda, Noriyoshi (PN Japan FSIP)" , Abhijit Menon-Sen , Dmitry Dolgov <9erthalion6@gmail.com>, Jeevan Ladhe , Mark Dilger , "pgsql-hackers@postgresql.org" , tushar Subject: Re: refactoring basebackup.c (zstd workers) In-reply-to: References: <20220311010223.GI28503@telsasoft.com> <20220312015253.zokhkwdn5xbbd4vf@alap3.anarazel.de> <20220314163547.GT28503@telsasoft.com> <20220314171152.GU28503@telsasoft.com> <20220317194130.GM28503@telsasoft.com> Comments: In-reply-to Robert Haas message dated "Sun, 20 Mar 2022 15:05:28 -0400" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1565807.1647803514.1@sss.pgh.pa.us> Date: Sun, 20 Mar 2022 15:11:54 -0400 Message-ID: <1565808.1647803514@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Robert Haas writes: >> Should this also set/check errno ? >> And check if value != ivalue_endp ? >> See strtol(3) > Even after reading the man page for strtol, it's not clear to me that > this is needed. That page represents checking *endptr != '\0' as > sufficient to tell whether an error occurred. I'm not sure whose man page you looked at, but the POSIX standard [1] has a pretty clear opinion about this: Since 0, {LONG_MIN} or {LLONG_MIN}, and {LONG_MAX} or {LLONG_MAX} are returned on error and are also valid returns on success, an application wishing to check for error situations should set errno to 0, then call strtol() or strtoll(), then check errno. Checking *endptr != '\0' is for detecting whether there is trailing garbage after the number; which may be an error case or not as you choose, but it's a different matter. regards, tom lane [1] https://pubs.opengroup.org/onlinepubs/9699919799/