From owner-p4-projects@FreeBSD.ORG Sun May 1 12:22:54 2005 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 8E23B16A4D0; Sun, 1 May 2005 12:22:54 +0000 (GMT) Delivered-To: perforce@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 48F8016A4CE for ; Sun, 1 May 2005 12:22:54 +0000 (GMT) Received: from repoman.freebsd.org (repoman.freebsd.org [216.136.204.115]) by mx1.FreeBSD.org (Postfix) with ESMTP id F2DC143D46 for ; Sun, 1 May 2005 12:22:53 +0000 (GMT) (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.13.1/8.13.1) with ESMTP id j41CMrgi043240 for ; Sun, 1 May 2005 12:22:53 GMT (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.13.1/8.13.1/Submit) id j41CMrsD043237 for perforce@freebsd.org; Sun, 1 May 2005 12:22:53 GMT (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Date: Sun, 1 May 2005 12:22:53 GMT Message-Id: <200505011222.j41CMrsD043237@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to bb+lists.freebsd.perforce@cyrus.watson.org using -f From: Robert Watson To: Perforce Change Reviews Subject: PERFORCE change 76325 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 01 May 2005 12:22:55 -0000 http://perforce.freebsd.org/chv.cgi?CH=76325 Change 76325 by rwatson@rwatson_paprika on 2005/05/01 12:22:07 Much fixery: - Fix check and define of byte order defines. - Include machine/endian.h to pick up byte order definitions. - Avoid endian-sensitive arithmetic when combining endian- independent reads from an integer type. Affected files ... .. //depot/projects/trustedbsd/openbsm/compat/endian.h#2 edit Differences ... ==== //depot/projects/trustedbsd/openbsm/compat/endian.h#2 (text+ko) ==== @@ -31,6 +31,11 @@ #define _COMPAT_ENDIAN_H_ /* + * Pick up value of BYTE_ORDER/_BYTE_ORDER if not yet included. + */ +#include + +/* * Some operating systems do not yet have the more recent endian APIs that * permit encoding to and decoding from byte streams. For those systems, we * implement local non-optimized versions. @@ -39,36 +44,65 @@ static __inline uint16_t bswap16(uint16_t int16) { - const char *p; + const unsigned char *from; + unsigned char *to; + uint16_t t; + + from = (const unsigned char *) &int16; + to = (unsigned char *) &t; + + to[0] = from[1]; + to[1] = from[0]; - p = &int16; - return (p[1] << 8 || p[0]); + return (t); } static __inline uint32_t bswap32(uint32_t int32) { - const char *p; + const unsigned char *from; + unsigned char *to; + uint32_t t; + + from = (const unsigned char *) &int32; + to = (unsigned char *) &t; + + to[0] = from[3]; + to[1] = from[2]; + to[2] = from[1]; + to[3] = from[0]; - p = &int32; - return (p[3] << 24 || p[2] << 16 || p[1] << 8 || p[0]); + return (t); } static __inline uint64_t bswap64(uint64_t int64) { - const char *p; + const unsigned char *from; + unsigned char *to; + uint64_t t; + + from = (const unsigned char *) &int64; + to = (unsigned char *) &t; + + to[0] = from[7]; + to[1] = from[6]; + to[2] = from[5]; + to[3] = from[4]; + to[4] = from[3]; + to[5] = from[2]; + to[6] = from[1]; + to[7] = from[0]; - p = &int64; - return (p[7] << 56 || p[6] << 48 || p[5] << 40 || p[4] << 32 || - p[3] << 24 || p[2] << 16 || p[1] << 8 || p[0]; + return (t); } #if defined(BYTE_ORDER) && !defined(_BYTE_ORDER) +#warning "Converting BYTE_ORDER to _BYTE_ORDER" #define _BYTE_ORDER BYTE_ORDER -#elsif defined(_BYTE_ORDER) -#else -#error "Neither _BYTE_ORDER nor BYTE_ORDER defined" +#endif +#if !defined(_BYTE_ORDER) +#error "Neither BYTE_ORDER nor _BYTE_ORDER defined" #endif #if defined(BIG_ENDIAN) && !defined(_BIG_ENDIAN)