From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:38993) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SbaGt-0002IJ-9R for qemu-devel@nongnu.org; Mon, 04 Jun 2012 12:36:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SbaGm-0006cw-BP for qemu-devel@nongnu.org; Mon, 04 Jun 2012 12:36:46 -0400 Received: from mx1.redhat.com ([209.132.183.28]:32907) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SbaGm-0006ci-3S for qemu-devel@nongnu.org; Mon, 04 Jun 2012 12:36:40 -0400 Message-ID: <4FCCE411.3020509@redhat.com> Date: Mon, 04 Jun 2012 10:36:33 -0600 From: Eric Blake 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> In-Reply-To: <4FCCE234.5040109@linux.vnet.ibm.com> Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="------------enigFF614F8E8CF4C2207D5FAEF4" 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: Corey Bryant Cc: kwolf@redhat.com, aliguori@us.ibm.com, qemu-devel@nongnu.org, stefanha@linux.vnet.ibm.com This is an OpenPGP/MIME signed message (RFC 2440 and 3156) --------------enigFF614F8E8CF4C2207D5FAEF4 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On 06/04/2012 10:28 AM, Corey Bryant wrote: >> But at least strtol lets you detect errors: >> >> char *tmp; >> errno =3D 0; >> fd =3D strtol(p,&tmp, 10); >> if (errno || tmp =3D=3D p) { >> /* raise your error here */ >> } >=20 > 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(). >=20 > 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. >=20 > Maybe a combination of isdigit() then strtol() will give a better idea > of success. Not necessary. --=20 Eric Blake eblake@redhat.com +1-919-301-3266 Libvirt virtualization library http://libvirt.org --------------enigFF614F8E8CF4C2207D5FAEF4 Content-Type: application/pgp-signature; name="signature.asc" Content-Description: OpenPGP digital signature Content-Disposition: attachment; filename="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.12 (GNU/Linux) Comment: Public key at http://people.redhat.com/eblake/eblake.gpg Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iQEcBAEBCAAGBQJPzOQRAAoJEKeha0olJ0NqnGEH+wQGL5+W7xNOZVA6JqMztcEn C9UasoOtKiKWcn0tgdU9r3GIBNagdSgvWybJbydZ+nR53o8x53LAXKocPwLVW6P+ Vb0u7JroJh52fG5DNN2kothZl7fuSZziqg91Ob/HrFw9NyaL8T29s6PIdvhIAqCB JvgIDTU7SABf0OGvOXs/pFwduhhUeHSUouBTOhYaGVugtcC/doKc+9nkjMauWU+N PGzt4nMZCEsVFdmfelypgaYkty+tRVd1/V819ddJaD5gHQOhnLzNCJ6SEZ9mavxd autCBD1zNfCtSthtKfoqdo4i0ntNkKx/AbGU94T11mGxp03abYTfrTgEM7ifngg= =Hl8L -----END PGP SIGNATURE----- --------------enigFF614F8E8CF4C2207D5FAEF4--