Subject: Re: Dumb/silly network programming question
To: #List NetBSD current users <current-users@NetBSD.ORG>
From: Christian Biere <christianbiere@gmx.de>
List: current-users
Date: 12/10/2003 03:27:21
--zYM0uCDKw75PZbzx
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

Bill Studenmund wrote:
> Then I get back the number of bytes read. If I get < 0, I got an error.

Well, the same manpage also says:

CAVEATS
     Error checks should explicitly test for -1.  Code such as

             while ((nr =3D read(fd, buf, sizeof(buf))) > 0)

     is not maximally portable, as some platforms allow for nbytes to range
     between SSIZE_MAX and SIZE_MAX - 2, in which case the return value of =
an
     error-free read() may appear as a negative number distinct from -1.
     Proper loops should use

             while ((nr =3D read(fd, buf, sizeof(buf))) !=3D -1 && nr !=3D =
0)


Maybe it's just me but everytime I see code which uses '< 0' or '>=3D 0'
I think "That's just not what the documentation says."
--=20
Christian

--zYM0uCDKw75PZbzx
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.3 (NetBSD)

iD8DBQE/1oSJ0KQix3oyIMcRAuLyAKC4YvOpb/VMkHQurmtUJ6weT/8ehQCePj1f
6GmIqAvKruxTI5vSNh/hzfc=
=CzYY
-----END PGP SIGNATURE-----

--zYM0uCDKw75PZbzx--