From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1HZwW9-0000V3-Cp for qemu-devel@nongnu.org; Fri, 06 Apr 2007 18:02:49 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1HZwW8-0000Ur-SH for qemu-devel@nongnu.org; Fri, 06 Apr 2007 18:02:49 -0400 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1HZwW8-0000Uo-Le for qemu-devel@nongnu.org; Fri, 06 Apr 2007 18:02:48 -0400 Received: from mail.codesourcery.com ([65.74.133.4]) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1HZwSb-0003Rx-FS for qemu-devel@nongnu.org; Fri, 06 Apr 2007 17:59:09 -0400 From: Paul Brook Subject: Re: [Qemu-devel] [patch] use socklen_t with getsockopt() Date: Fri, 6 Apr 2007 22:59:00 +0100 References: <343495.72027.qm@web25708.mail.ukl.yahoo.com> <20070405104220.GA27936@mail.shareable.org> <200704061751.28458.vapier@gentoo.org> In-Reply-To: <200704061751.28458.vapier@gentoo.org> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Message-Id: <200704062259.01789.paul@codesourcery.com> Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Sylvain Petreolle , Mike Frysinger On Friday 06 April 2007 22:51, Mike Frysinger wrote: > On Thursday 05 April 2007, Jamie Lokier wrote: > > Sylvain Petreolle wrote: > > > Was incorrect before too, since it was sizeof(int) in the first place= ? > > > > The old type of "val" was "int", so it made no different to the size. > > When "val" is of type socklen_t, it matters. > > val is still of type int which is fine ... socklen_t is for the variable > which describes the length of val It's worth noting that socklen_t should be "int" anyway. =46rom the accept(2) manpage: NOTE The third argument of accept() was originally declared as an `int= *' (and is that under libc4 and libc5 and on many other systems like = 4.x BSD, SunOS 4, SGI); a POSIX.1g draft standard wanted to change it i= nto a `size_t *', and that is what it is for SunOS 5. Later POSIX dra= fts have `socklen_t *', and so do the Single Unix Specification and glib= c2. Quoting Linus Torvalds: "_Any_ sane library _must_ have "socklen_t" be the same size as i= nt. Anything else breaks any BSD socket layer stuff. POSIX initially = did make it a size_t, and I (and hopefully others, but obviously not = too many) complained to them very loudly indeed. Making it a size_t= is completely broken, exactly because size_t very seldom is the same s= ize as "int" on 64-bit architectures, for example. And it has to be = the same size as "int" because that's what the BSD socket interface = is. Anyway, the POSIX people eventually got a clue, and crea= ted "socklen_t". They shouldn't have touched it in the first place, = but once they did they felt it had to have a named type for some unfa= th- omable reason (probably somebody didn't like losing face over hav= ing done the original stupid thing, so they silently just renamed th= eir blunder)."