From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:57724) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SbaKs-0003x4-Ud for qemu-devel@nongnu.org; Mon, 04 Jun 2012 12:40:59 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SbaKr-0007Dm-4Q for qemu-devel@nongnu.org; Mon, 04 Jun 2012 12:40:54 -0400 Received: from e35.co.us.ibm.com ([32.97.110.153]:54639) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SbaKq-0007DO-UA for qemu-devel@nongnu.org; Mon, 04 Jun 2012 12:40:53 -0400 Received: from /spool/local by e35.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 4 Jun 2012 10:40:46 -0600 Received: from d01relay06.pok.ibm.com (d01relay06.pok.ibm.com [9.56.227.116]) by d01dlp03.pok.ibm.com (Postfix) with ESMTP id B961EC90058 for ; Mon, 4 Jun 2012 12:40:25 -0400 (EDT) Received: from d01av02.pok.ibm.com (d01av02.pok.ibm.com [9.56.224.216]) by d01relay06.pok.ibm.com (8.13.8/8.13.8/NCO v10.0) with ESMTP id q54GePZu26214414 for ; Mon, 4 Jun 2012 12:40:25 -0400 Received: from d01av02.pok.ibm.com (loopback [127.0.0.1]) by d01av02.pok.ibm.com (8.14.4/8.13.1/NCO v10.0 AVout) with ESMTP id q54GeODF030502 for ; Mon, 4 Jun 2012 13:40:24 -0300 Message-ID: <4FCCE4F5.50000@linux.vnet.ibm.com> Date: Mon, 04 Jun 2012 12:40:21 -0400 From: Corey Bryant MIME-Version: 1.0 References: <1338815410-24890-1-git-send-email-coreyb@linux.vnet.ibm.com> <1338815410-24890-3-git-send-email-coreyb@linux.vnet.ibm.com> <4FCCC6F8.3010901@redhat.com> <4FCCD987.8080205@linux.vnet.ibm.com> <4FCCDC55.5070705@redhat.com> <4FCCE234.5040109@linux.vnet.ibm.com> <4FCCE411.3020509@redhat.com> In-Reply-To: <4FCCE411.3020509@redhat.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH 2/3] block: Add support to "open" /dev/fd/X filenames List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Eric Blake Cc: kwolf@redhat.com, aliguori@us.ibm.com, qemu-devel@nongnu.org, stefanha@linux.vnet.ibm.com On 06/04/2012 12:36 PM, Eric Blake wrote: > On 06/04/2012 10:28 AM, Corey Bryant wrote: > >>> But at least strtol lets you detect errors: >>> >>> char *tmp; >>> errno = 0; >>> fd = strtol(p,&tmp, 10); >>> if (errno || tmp == p) { >>> /* raise your error here */ >>> } >> >> I don't think this is legitimate. errno can be set under the covers of >> library calls even if the strtol() call is successful. > > Wrong. POSIX _specifically_ requires that strtol() leave errno > unchanged unless strtol() is reporting a failure, no matter what other > library calls (if any) are made under the covers by strtol(). > > In other words, pre-setting errno to 0, then calling strtol(), then > checking errno, _is_ the documented way to check for strtol() failures, > and a correct usage of strtol() MUST use this method. See also commit > 6b0e33be88bbccc3bcb987026089aa09f9622de9. atoi() does not have this > same guarantee, which makes atoi() worthless at detecting errors in > relation to strtol(). > Great! I see it now (excerpt below is from the opengroup specification). This is definitely an exception from normal behavior of C APIs. "The strtol() function will not change the setting of errno if successful." >> >> I was thinking if strtol returns 0 and errno is 0, perhaps we could >> assume success, but I don't think this is guaranteed either. > > Actually, it _is_ guaranteed - if you pre-set errno to 0, then call > strtol(), then errno is still 0, then the result did not encounter an > error, so a result of 0 at that point means that you indeed parsed a 0. > >> >> Maybe a combination of isdigit() then strtol() will give a better idea >> of success. > > Not necessary. > -- Regards, Corey