From owner-cvs-all Sat Sep 14 3:15: 6 2002 Delivered-To: cvs-all@freebsd.org Received: from mx1.FreeBSD.org (mx1.FreeBSD.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 7498B37B400; Sat, 14 Sep 2002 03:15:02 -0700 (PDT) Received: from critter.freebsd.dk (critter.freebsd.dk [212.242.86.163]) by mx1.FreeBSD.org (Postfix) with ESMTP id B840143E4A; Sat, 14 Sep 2002 03:15:01 -0700 (PDT) (envelope-from phk@critter.freebsd.dk) Received: from critter.freebsd.dk (localhost [127.0.0.1]) by critter.freebsd.dk (8.12.3/8.12.2) with ESMTP id g8EAErB9016316; Sat, 14 Sep 2002 12:14:54 +0200 (CEST) (envelope-from phk@critter.freebsd.dk) To: "Greg 'groggy' Lehey" Cc: cvs-committers@FreeBSD.org, cvs-all@FreeBSD.org Subject: Re: cvs commit: src/sys/geom geom.h geom_enc.c In-Reply-To: Your message of "Sat, 14 Sep 2002 11:00:12 +0930." <20020914013012.GU25003@wantadilla.lemis.com> Date: Sat, 14 Sep 2002 12:14:52 +0200 Message-ID: <16315.1031998492@critter.freebsd.dk> From: Poul-Henning Kamp Sender: owner-cvs-all@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG In message <20020914013012.GU25003@wantadilla.lemis.com>, "Greg 'groggy' Lehey" writes: >On Friday, 13 September 2002 at 3:33:10 -0700, Poul-Henning Kamp wrote: >> phk 2002/09/13 03:33:10 PDT >> >> Modified files: >> sys/geom geom.h geom_enc.c >> Log: >> Add a couple more of the big/little-endian conversion routines and make >> them visible from userland, if need be. >> >> I wish that the C language contained this as part of struct definintions, >> but failing that, I would settle for an agreed upon set of functions for >> packing/unpacking integers in various sizes from byte-streams which may >> have unfriendly alignment. > >Is there any reason not to use the Linux function names (be32_to_cpu, >cpu_to_le16, etc.)? The linux functions, as far as I can tell are: uint32_t be32_to_cpu(uint32_t); uint32_t cpu_to_be32(uint32_t); Which results in code like: uint32_t u; something *ptr; #ifdef CPU_WITH_STRICT_ALIGNMENT bcopy(ptr, &u, sizeof u); #else u = *(uint32_t)ptr; #endif u = be32_to_cpu(u); I think it is far more logical to have: uint32_t be32_dec(void *); void be32_enc(uint32_t, void *); Resulting in code like: uint32_t u; something *ptr; u = be32_dec(ptr); -- Poul-Henning Kamp | UNIX since Zilog Zeus 3.20 phk@FreeBSD.ORG | TCP/IP since RFC 956 FreeBSD committer | BSD since 4.3-tahoe Never attribute to malice what can adequately be explained by incompetence. To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe cvs-all" in the body of the message