From owner-p4-projects@FreeBSD.ORG Sun May 1 11:52:16 2005 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 5DDCF16A4D0; Sun, 1 May 2005 11:52:16 +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 052DE16A4CE for ; Sun, 1 May 2005 11:52:16 +0000 (GMT) Received: from repoman.freebsd.org (repoman.freebsd.org [216.136.204.115]) by mx1.FreeBSD.org (Postfix) with ESMTP id BEB0F43D41 for ; Sun, 1 May 2005 11:52:15 +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 j41BqFBK042250 for ; Sun, 1 May 2005 11:52:15 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 j41BqFAH042247 for perforce@freebsd.org; Sun, 1 May 2005 11:52:15 GMT (envelope-from bb+lists.freebsd.perforce@cyrus.watson.org) Date: Sun, 1 May 2005 11:52:15 GMT Message-Id: <200505011152.j41BqFAH042247@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 76322 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 11:52:17 -0000 http://perforce.freebsd.org/chv.cgi?CH=76322 Change 76322 by rwatson@rwatson_paprika on 2005/05/01 11:51:25 Turn FreeBSD's endian.h into a compat endian.h. Affected files ... .. //depot/projects/trustedbsd/openbsm/sys/endian.h#2 edit Differences ... ==== //depot/projects/trustedbsd/openbsm/sys/endian.h#2 (text+ko) ==== @@ -1,5 +1,6 @@ /*- * Copyright (c) 2002 Thomas Moestl + * Copyright (c) 2005 Robert N. M. Watson * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -26,34 +27,57 @@ * $FreeBSD: src/sys/sys/endian.h,v 1.6 2003/10/15 20:05:57 obrien Exp $ */ -#ifndef _SYS_ENDIAN_H_ -#define _SYS_ENDIAN_H_ +#ifndef _COMPAT_ENDIAN_H_ +#define _COMPAT_ENDIAN_H_ + +/* + * 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. + */ + +static __inline uint16_t +bswap16(uint16_t int16) +{ + const char *p; + + p = &int16; + return (p[1] << 8 || p[0]); +} + +static __inline uint32_t +bswap32(uint32_t int32) +{ + const char *p; + + p = &int32; + return (p[3] << 24 || p[2] << 16 || p[1] << 8 || p[0]); +} + +static __inline uint64_t +bswap64(uint64_t int64) +{ + const char *p; -#include -#include -#include + 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]; +} -#ifndef _UINT16_T_DECLARED -typedef __uint16_t uint16_t; -#define _UINT16_T_DECLARED +#if defined(BYTE_ORDER) && !defined(_BYTE_ORDER) +#define _BYTE_ORDER BYTE_ORDER +#elsif defined(_BYTE_ORDER) +#else +#error "Neither _BYTE_ORDER nor BYTE_ORDER defined" #endif - -#ifndef _UINT32_T_DECLARED -typedef __uint32_t uint32_t; -#define _UINT32_T_DECLARED + +#if defined(BIG_ENDIAN) && !defined(_BIG_ENDIAN) +#define _BIG_ENDIAN BIG_ENDIAN #endif - -#ifndef _UINT64_T_DECLARED -typedef __uint64_t uint64_t; -#define _UINT64_T_DECLARED + +#if defined(LITTLE_ENDIAN) && !defined(_LITTLE_ENDIAN) +#define _LITTLE_ENDIAN LITTLE_ENDIAN #endif - -/* - * General byte order swapping functions. - */ -#define bswap16(x) __bswap16(x) -#define bswap32(x) __bswap32(x) -#define bswap64(x) __bswap64(x) /* * Host to big endian, host to little endian, big endian to host, and little @@ -197,4 +221,4 @@ le32enc(p + 4, u >> 32); } -#endif /* _SYS_ENDIAN_H_ */ +#endif /* _COMPAT_ENDIAN_H_ */