diff options
author | H. Peter Anvin <hpa@zytor.com> | 2002-08-12 01:30:55 +0000 |
---|---|---|
committer | H. Peter Anvin <hpa@zytor.com> | 2002-08-12 01:30:55 +0000 |
commit | d580c2d25ede73d4a8568e5d3672080082d52246 (patch) | |
tree | 797acfcf3898cdcd10e375e29c119a88eece3c2d | |
parent | 4122764ace9a7548677a28ae921a592727a6345a (diff) | |
download | klibc-d580c2d25ede73d4a8568e5d3672080082d52246.tar.gz |
The kernels endian handing is better than ours -- use the kernel.klibc-0.20
46 files changed, 60 insertions, 530 deletions
diff --git a/arch/alpha/include/klibc/endian.h b/arch/alpha/include/klibc/endian.h deleted file mode 100644 index 9aaeeb490933f..0000000000000 --- a/arch/alpha/include/klibc/endian.h +++ /dev/null @@ -1,10 +0,0 @@ -/* - * arch/alpha/include/klibc/endian.h - */ - -#ifndef _KLIBC_ENDIAN_H -#define _KLIBC_ENDIAN_H - -#define __BYTE_ORDER __LITTLE_ENDIAN - -#endif /* _KLIBC_ENDIAN_H */ diff --git a/arch/arm/include/klibc/endian.h b/arch/arm/include/klibc/endian.h deleted file mode 100644 index 647c1aff0e40d..0000000000000 --- a/arch/arm/include/klibc/endian.h +++ /dev/null @@ -1,10 +0,0 @@ -/* - * arch/arm/include/klibc/endian.h - */ - -#ifndef _KLIBC_ENDIAN_H -#define _KLIBC_ENDIAN_H - -#define __BYTE_ORDER __LITTLE_ENDIAN - -#endif /* _KLIBC_ENDIAN_H */ diff --git a/arch/i386/include/klibc/endian.h b/arch/i386/include/klibc/endian.h deleted file mode 100644 index f7ab7a71fd751..0000000000000 --- a/arch/i386/include/klibc/endian.h +++ /dev/null @@ -1,10 +0,0 @@ -/* - * arch/i386/include/klibc/endian.h - */ - -#ifndef _KLIBC_ENDIAN_H -#define _KLIBC_ENDIAN_H - -#define __BYTE_ORDER __LITTLE_ENDIAN - -#endif /* _KLIBC_ENDIAN_H */ diff --git a/arch/ia64/include/klibc/endian.h b/arch/ia64/include/klibc/endian.h deleted file mode 100644 index fc7a38c0d9946..0000000000000 --- a/arch/ia64/include/klibc/endian.h +++ /dev/null @@ -1,10 +0,0 @@ -/* - * arch/ia64/include/klibc/endian.h - */ - -#ifndef _KLIBC_ENDIAN_H -#define _KLIBC_ENDIAN_H - -#define __BYTE_ORDER __LITTLE_ENDIAN - -#endif /* _KLIBC_ENDIAN_H */ diff --git a/arch/m68k/include/klibc/endian.h b/arch/m68k/include/klibc/endian.h deleted file mode 100644 index 93735ca2fdf80..0000000000000 --- a/arch/m68k/include/klibc/endian.h +++ /dev/null @@ -1,10 +0,0 @@ -/* - * arch/m68k/include/klibc/endian.h - */ - -#ifndef _KLIBC_ENDIAN_H -#define _KLIBC_ENDIAN_H - -#define __BYTE_ORDER __BIG_ENDIAN - -#endif /* _KLIBC_ENDIAN_H */ diff --git a/arch/mips/include/klibc/endian.h b/arch/mips/include/klibc/endian.h deleted file mode 100644 index 1097fe7cd3575..0000000000000 --- a/arch/mips/include/klibc/endian.h +++ /dev/null @@ -1,16 +0,0 @@ -/* - * arch/mips/include/klibc/endian.h - */ - -#ifndef _KLIBC_ENDIAN_H -#define _KLIBC_ENDIAN_H - -#if defined(__MIPSEB__) -# define __BYTE_ORDER __BIG_ENDIAN -#elif defined(__MIPSEL__) -# define __BYTE_ORDER __LITTLE_ENDIAN -#else -# error "Neither __MIPSEB__ nor __MIPSEL__ defined" -#endif - -#endif /* _KLIBC_ENDIAN_H */ diff --git a/arch/mips64/include/klibc/endian.h b/arch/mips64/include/klibc/endian.h deleted file mode 100644 index ba46179a0a20b..0000000000000 --- a/arch/mips64/include/klibc/endian.h +++ /dev/null @@ -1,16 +0,0 @@ -/* - * arch/mips64/include/klibc/endian.h - */ - -#ifndef _KLIBC_ENDIAN_H -#define _KLIBC_ENDIAN_H - -#if defined(__MIPSEB__) -# define __BYTE_ORDER __BIG_ENDIAN -#elif defined(__MIPSEL__) -# define __BYTE_ORDER __LITTLE_ENDIAN -#else -# error "Neither __MIPSEB__ nor __MIPSEL__ defined" -#endif - -#endif /* _KLIBC_ENDIAN_H */ diff --git a/arch/parisc/include/klibc/endian.h b/arch/parisc/include/klibc/endian.h deleted file mode 100644 index d849f7227ebb3..0000000000000 --- a/arch/parisc/include/klibc/endian.h +++ /dev/null @@ -1,10 +0,0 @@ -/* - * arch/parisc/include/klibc/endian.h - */ - -#ifndef _KLIBC_ENDIAN_H -#define _KLIBC_ENDIAN_H - -#define __BYTE_ORDER __BIG_ENDIAN - -#endif /* _KLIBC_ENDIAN_H */ diff --git a/arch/ppc/include/klibc/endian.h b/arch/ppc/include/klibc/endian.h deleted file mode 100644 index ba42645519313..0000000000000 --- a/arch/ppc/include/klibc/endian.h +++ /dev/null @@ -1,10 +0,0 @@ -/* - * arch/ppc/include/klibc/endian.h - */ - -#ifndef _KLIBC_ENDIAN_H -#define _KLIBC_ENDIAN_H - -#define __BYTE_ORDER __BIG_ENDIAN - -#endif /* _KLIBC_ENDIAN_H */ diff --git a/arch/ppc64/include/klibc/endian.h b/arch/ppc64/include/klibc/endian.h deleted file mode 100644 index eb18078b25cfe..0000000000000 --- a/arch/ppc64/include/klibc/endian.h +++ /dev/null @@ -1,10 +0,0 @@ -/* - * arch/ppc64/include/klibc/endian.h - */ - -#ifndef _KLIBC_ENDIAN_H -#define _KLIBC_ENDIAN_H - -#define __BYTE_ORDER __BIG_ENDIAN - -#endif /* _KLIBC_ENDIAN_H */ diff --git a/arch/s390/include/klibc/endian.h b/arch/s390/include/klibc/endian.h deleted file mode 100644 index f30347a73531f..0000000000000 --- a/arch/s390/include/klibc/endian.h +++ /dev/null @@ -1,10 +0,0 @@ -/* - * arch/s390/include/klibc/endian.h - */ - -#ifndef _KLIBC_ENDIAN_H -#define _KLIBC_ENDIAN_H - -#define __BYTE_ORDER __BIG_ENDIAN - -#endif /* _KLIBC_ENDIAN_H */ diff --git a/arch/s390x/include/klibc/endian.h b/arch/s390x/include/klibc/endian.h deleted file mode 100644 index 87218fd94df80..0000000000000 --- a/arch/s390x/include/klibc/endian.h +++ /dev/null @@ -1,10 +0,0 @@ -/* - * arch/s390x/include/klibc/endian.h - */ - -#ifndef _KLIBC_ENDIAN_H -#define _KLIBC_ENDIAN_H - -#define __BYTE_ORDER __BIG_ENDIAN - -#endif /* _KLIBC_ENDIAN_H */ diff --git a/arch/sparc/include/klibc/endian.h b/arch/sparc/include/klibc/endian.h deleted file mode 100644 index 39c4897d3c7de..0000000000000 --- a/arch/sparc/include/klibc/endian.h +++ /dev/null @@ -1,10 +0,0 @@ -/* - * arch/sparc/include/klibc/endian.h - */ - -#ifndef _KLIBC_ENDIAN_H -#define _KLIBC_ENDIAN_H - -#define __BYTE_ORDER __BIG_ENDIAN - -#endif /* _KLIBC_ENDIAN_H */ diff --git a/arch/sparc64/include/klibc/endian.h b/arch/sparc64/include/klibc/endian.h deleted file mode 100644 index 5c099821cdb87..0000000000000 --- a/arch/sparc64/include/klibc/endian.h +++ /dev/null @@ -1,10 +0,0 @@ -/* - * arch/sparc64/include/klibc/endian.h - */ - -#ifndef _KLIBC_ENDIAN_H -#define _KLIBC_ENDIAN_H - -#define __BYTE_ORDER __BIG_ENDIAN - -#endif /* _KLIBC_ENDIAN_H */ diff --git a/include/arch/alpha/klibc/endian.h b/include/arch/alpha/klibc/endian.h deleted file mode 100644 index 9aaeeb490933f..0000000000000 --- a/include/arch/alpha/klibc/endian.h +++ /dev/null @@ -1,10 +0,0 @@ -/* - * arch/alpha/include/klibc/endian.h - */ - -#ifndef _KLIBC_ENDIAN_H -#define _KLIBC_ENDIAN_H - -#define __BYTE_ORDER __LITTLE_ENDIAN - -#endif /* _KLIBC_ENDIAN_H */ diff --git a/include/arch/arm/klibc/endian.h b/include/arch/arm/klibc/endian.h deleted file mode 100644 index 647c1aff0e40d..0000000000000 --- a/include/arch/arm/klibc/endian.h +++ /dev/null @@ -1,10 +0,0 @@ -/* - * arch/arm/include/klibc/endian.h - */ - -#ifndef _KLIBC_ENDIAN_H -#define _KLIBC_ENDIAN_H - -#define __BYTE_ORDER __LITTLE_ENDIAN - -#endif /* _KLIBC_ENDIAN_H */ diff --git a/include/arch/i386/klibc/endian.h b/include/arch/i386/klibc/endian.h deleted file mode 100644 index f7ab7a71fd751..0000000000000 --- a/include/arch/i386/klibc/endian.h +++ /dev/null @@ -1,10 +0,0 @@ -/* - * arch/i386/include/klibc/endian.h - */ - -#ifndef _KLIBC_ENDIAN_H -#define _KLIBC_ENDIAN_H - -#define __BYTE_ORDER __LITTLE_ENDIAN - -#endif /* _KLIBC_ENDIAN_H */ diff --git a/include/arch/ia64/klibc/endian.h b/include/arch/ia64/klibc/endian.h deleted file mode 100644 index fc7a38c0d9946..0000000000000 --- a/include/arch/ia64/klibc/endian.h +++ /dev/null @@ -1,10 +0,0 @@ -/* - * arch/ia64/include/klibc/endian.h - */ - -#ifndef _KLIBC_ENDIAN_H -#define _KLIBC_ENDIAN_H - -#define __BYTE_ORDER __LITTLE_ENDIAN - -#endif /* _KLIBC_ENDIAN_H */ diff --git a/include/arch/m68k/klibc/endian.h b/include/arch/m68k/klibc/endian.h deleted file mode 100644 index 93735ca2fdf80..0000000000000 --- a/include/arch/m68k/klibc/endian.h +++ /dev/null @@ -1,10 +0,0 @@ -/* - * arch/m68k/include/klibc/endian.h - */ - -#ifndef _KLIBC_ENDIAN_H -#define _KLIBC_ENDIAN_H - -#define __BYTE_ORDER __BIG_ENDIAN - -#endif /* _KLIBC_ENDIAN_H */ diff --git a/include/arch/mips/klibc/endian.h b/include/arch/mips/klibc/endian.h deleted file mode 100644 index 1097fe7cd3575..0000000000000 --- a/include/arch/mips/klibc/endian.h +++ /dev/null @@ -1,16 +0,0 @@ -/* - * arch/mips/include/klibc/endian.h - */ - -#ifndef _KLIBC_ENDIAN_H -#define _KLIBC_ENDIAN_H - -#if defined(__MIPSEB__) -# define __BYTE_ORDER __BIG_ENDIAN -#elif defined(__MIPSEL__) -# define __BYTE_ORDER __LITTLE_ENDIAN -#else -# error "Neither __MIPSEB__ nor __MIPSEL__ defined" -#endif - -#endif /* _KLIBC_ENDIAN_H */ diff --git a/include/arch/mips64/klibc/endian.h b/include/arch/mips64/klibc/endian.h deleted file mode 100644 index ba46179a0a20b..0000000000000 --- a/include/arch/mips64/klibc/endian.h +++ /dev/null @@ -1,16 +0,0 @@ -/* - * arch/mips64/include/klibc/endian.h - */ - -#ifndef _KLIBC_ENDIAN_H -#define _KLIBC_ENDIAN_H - -#if defined(__MIPSEB__) -# define __BYTE_ORDER __BIG_ENDIAN -#elif defined(__MIPSEL__) -# define __BYTE_ORDER __LITTLE_ENDIAN -#else -# error "Neither __MIPSEB__ nor __MIPSEL__ defined" -#endif - -#endif /* _KLIBC_ENDIAN_H */ diff --git a/include/arch/parisc/klibc/endian.h b/include/arch/parisc/klibc/endian.h deleted file mode 100644 index d849f7227ebb3..0000000000000 --- a/include/arch/parisc/klibc/endian.h +++ /dev/null @@ -1,10 +0,0 @@ -/* - * arch/parisc/include/klibc/endian.h - */ - -#ifndef _KLIBC_ENDIAN_H -#define _KLIBC_ENDIAN_H - -#define __BYTE_ORDER __BIG_ENDIAN - -#endif /* _KLIBC_ENDIAN_H */ diff --git a/include/arch/ppc/klibc/endian.h b/include/arch/ppc/klibc/endian.h deleted file mode 100644 index ba42645519313..0000000000000 --- a/include/arch/ppc/klibc/endian.h +++ /dev/null @@ -1,10 +0,0 @@ -/* - * arch/ppc/include/klibc/endian.h - */ - -#ifndef _KLIBC_ENDIAN_H -#define _KLIBC_ENDIAN_H - -#define __BYTE_ORDER __BIG_ENDIAN - -#endif /* _KLIBC_ENDIAN_H */ diff --git a/include/arch/ppc64/klibc/endian.h b/include/arch/ppc64/klibc/endian.h deleted file mode 100644 index eb18078b25cfe..0000000000000 --- a/include/arch/ppc64/klibc/endian.h +++ /dev/null @@ -1,10 +0,0 @@ -/* - * arch/ppc64/include/klibc/endian.h - */ - -#ifndef _KLIBC_ENDIAN_H -#define _KLIBC_ENDIAN_H - -#define __BYTE_ORDER __BIG_ENDIAN - -#endif /* _KLIBC_ENDIAN_H */ diff --git a/include/arch/s390/klibc/endian.h b/include/arch/s390/klibc/endian.h deleted file mode 100644 index f30347a73531f..0000000000000 --- a/include/arch/s390/klibc/endian.h +++ /dev/null @@ -1,10 +0,0 @@ -/* - * arch/s390/include/klibc/endian.h - */ - -#ifndef _KLIBC_ENDIAN_H -#define _KLIBC_ENDIAN_H - -#define __BYTE_ORDER __BIG_ENDIAN - -#endif /* _KLIBC_ENDIAN_H */ diff --git a/include/arch/s390x/klibc/endian.h b/include/arch/s390x/klibc/endian.h deleted file mode 100644 index 87218fd94df80..0000000000000 --- a/include/arch/s390x/klibc/endian.h +++ /dev/null @@ -1,10 +0,0 @@ -/* - * arch/s390x/include/klibc/endian.h - */ - -#ifndef _KLIBC_ENDIAN_H -#define _KLIBC_ENDIAN_H - -#define __BYTE_ORDER __BIG_ENDIAN - -#endif /* _KLIBC_ENDIAN_H */ diff --git a/include/arch/sparc/klibc/endian.h b/include/arch/sparc/klibc/endian.h deleted file mode 100644 index 39c4897d3c7de..0000000000000 --- a/include/arch/sparc/klibc/endian.h +++ /dev/null @@ -1,10 +0,0 @@ -/* - * arch/sparc/include/klibc/endian.h - */ - -#ifndef _KLIBC_ENDIAN_H -#define _KLIBC_ENDIAN_H - -#define __BYTE_ORDER __BIG_ENDIAN - -#endif /* _KLIBC_ENDIAN_H */ diff --git a/include/arch/sparc64/klibc/endian.h b/include/arch/sparc64/klibc/endian.h deleted file mode 100644 index 5c099821cdb87..0000000000000 --- a/include/arch/sparc64/klibc/endian.h +++ /dev/null @@ -1,10 +0,0 @@ -/* - * arch/sparc64/include/klibc/endian.h - */ - -#ifndef _KLIBC_ENDIAN_H -#define _KLIBC_ENDIAN_H - -#define __BYTE_ORDER __BIG_ENDIAN - -#endif /* _KLIBC_ENDIAN_H */ diff --git a/include/endian.h b/include/endian.h index 7a3680dd11d40..348d659a4cce1 100644 --- a/include/endian.h +++ b/include/endian.h @@ -5,11 +5,33 @@ #ifndef _ENDIAN_H #define _ENDIAN_H -#define __LITTLE_ENDIAN 1234 -#define __BIG_ENDIAN 4321 -#define __PDP_ENDIAN 3412 +#include <asm/byteorder.h> -#include <klibc/endian.h> +/* Linux' asm/byteorder.h defines either __LITTLE_ENDIAN or __BIG_ENDIAN, + but the BSD-ish macros expect both to be defined with __BYTE_ORDER + defining which is actually used... */ + +#if defined(__LITTLE_ENDIAN) +# undef __LITTLE_ENDIAN +# define __LITTLE_ENDIAN 1234 +# define __BIG_ENDIAN 4321 +# define __PDP_ENDIAN 3412 +# define __BYTE_ORDER __LITTLE_ENDIAN +#elif defined(__BIG_ENDIAN) +# undef __BIG_ENDIAN +# define __LITTLE_ENDIAN 1234 +# define __BIG_ENDIAN 4321 +# define __PDP_ENDIAN 3412 +# define __BYTE_ORDER __BIG_ENDIAN +#elif defined(__PDP_ENDIAN) +# undef __PDP_ENDIAN +# define __LITTLE_ENDIAN 1234 +# define __BIG_ENDIAN 4321 +# define __PDP_ENDIAN 3412 +# define __BYTE_ORDER __PDP_ENDIAN +#else +# error "Unknown byte order!" +#endif #define LITTLE_ENDIAN __LITTLE_ENDIAN #define BIG_ENDIAN __BIG_ENDIAN diff --git a/include/netinet/in.h b/include/netinet/in.h index c1f1c164fd359..4b7e77ee7d188 100644 --- a/include/netinet/in.h +++ b/include/netinet/in.h @@ -8,38 +8,9 @@ #include <stdint.h> #include <endian.h> -#if __BYTE_ORDER == __BIG_ENDIAN - -#define htonl(x) ((uint32_t)(x)) -#define ntohl(x) ((uint32_t)(x)) -#define htons(x) ((uint16_t)(x)) -#define ntohs(x) ((uint16_t)(x)) - -#elif __BYTE_ORDER == __LITTLE_ENDIAN - -static __inline__ -uint32_t htonl(uint32_t __x) -{ -#if defined(__i486__)||defined(__pentium__)||defined(__pentiumpro__) - asm("bswap %0" : "+rm" (__x)); - return __x; -#else - return (__x >> 24) + ((__x >> 8) & 0xff00) + - ((__x & 0xff00) << 8) + (__x << 24); -#endif -} - -static __inline__ -uint16_t htons(uint16_t __x) -{ - return (__x >> 8) + (__x << 8); -} - -#define htonl(x) htonl(x) -#define ntohl(x) htohl(x) -#define htons(x) htons(x) -#define ntohs(x) htons(x) - -#endif /* endian */ +#define htons(x) __cpu_to_be16(x) +#define ntohs(x) __be16_to_cpu(x) +#define htonl(x) __cpu_to_be32(x) +#define ntohl(x) __be32_to_cpu(x) #endif /* _NETINET_IN_H */ diff --git a/klibc/arch/alpha/include/klibc/endian.h b/klibc/arch/alpha/include/klibc/endian.h deleted file mode 100644 index 9aaeeb490933f..0000000000000 --- a/klibc/arch/alpha/include/klibc/endian.h +++ /dev/null @@ -1,10 +0,0 @@ -/* - * arch/alpha/include/klibc/endian.h - */ - -#ifndef _KLIBC_ENDIAN_H -#define _KLIBC_ENDIAN_H - -#define __BYTE_ORDER __LITTLE_ENDIAN - -#endif /* _KLIBC_ENDIAN_H */ diff --git a/klibc/arch/arm/include/klibc/endian.h b/klibc/arch/arm/include/klibc/endian.h deleted file mode 100644 index 647c1aff0e40d..0000000000000 --- a/klibc/arch/arm/include/klibc/endian.h +++ /dev/null @@ -1,10 +0,0 @@ -/* - * arch/arm/include/klibc/endian.h - */ - -#ifndef _KLIBC_ENDIAN_H -#define _KLIBC_ENDIAN_H - -#define __BYTE_ORDER __LITTLE_ENDIAN - -#endif /* _KLIBC_ENDIAN_H */ diff --git a/klibc/arch/i386/include/klibc/endian.h b/klibc/arch/i386/include/klibc/endian.h deleted file mode 100644 index f7ab7a71fd751..0000000000000 --- a/klibc/arch/i386/include/klibc/endian.h +++ /dev/null @@ -1,10 +0,0 @@ -/* - * arch/i386/include/klibc/endian.h - */ - -#ifndef _KLIBC_ENDIAN_H -#define _KLIBC_ENDIAN_H - -#define __BYTE_ORDER __LITTLE_ENDIAN - -#endif /* _KLIBC_ENDIAN_H */ diff --git a/klibc/arch/ia64/include/klibc/endian.h b/klibc/arch/ia64/include/klibc/endian.h deleted file mode 100644 index fc7a38c0d9946..0000000000000 --- a/klibc/arch/ia64/include/klibc/endian.h +++ /dev/null @@ -1,10 +0,0 @@ -/* - * arch/ia64/include/klibc/endian.h - */ - -#ifndef _KLIBC_ENDIAN_H -#define _KLIBC_ENDIAN_H - -#define __BYTE_ORDER __LITTLE_ENDIAN - -#endif /* _KLIBC_ENDIAN_H */ diff --git a/klibc/arch/m68k/include/klibc/endian.h b/klibc/arch/m68k/include/klibc/endian.h deleted file mode 100644 index 93735ca2fdf80..0000000000000 --- a/klibc/arch/m68k/include/klibc/endian.h +++ /dev/null @@ -1,10 +0,0 @@ -/* - * arch/m68k/include/klibc/endian.h - */ - -#ifndef _KLIBC_ENDIAN_H -#define _KLIBC_ENDIAN_H - -#define __BYTE_ORDER __BIG_ENDIAN - -#endif /* _KLIBC_ENDIAN_H */ diff --git a/klibc/arch/mips/include/klibc/endian.h b/klibc/arch/mips/include/klibc/endian.h deleted file mode 100644 index 1097fe7cd3575..0000000000000 --- a/klibc/arch/mips/include/klibc/endian.h +++ /dev/null @@ -1,16 +0,0 @@ -/* - * arch/mips/include/klibc/endian.h - */ - -#ifndef _KLIBC_ENDIAN_H -#define _KLIBC_ENDIAN_H - -#if defined(__MIPSEB__) -# define __BYTE_ORDER __BIG_ENDIAN -#elif defined(__MIPSEL__) -# define __BYTE_ORDER __LITTLE_ENDIAN -#else -# error "Neither __MIPSEB__ nor __MIPSEL__ defined" -#endif - -#endif /* _KLIBC_ENDIAN_H */ diff --git a/klibc/arch/mips64/include/klibc/endian.h b/klibc/arch/mips64/include/klibc/endian.h deleted file mode 100644 index ba46179a0a20b..0000000000000 --- a/klibc/arch/mips64/include/klibc/endian.h +++ /dev/null @@ -1,16 +0,0 @@ -/* - * arch/mips64/include/klibc/endian.h - */ - -#ifndef _KLIBC_ENDIAN_H -#define _KLIBC_ENDIAN_H - -#if defined(__MIPSEB__) -# define __BYTE_ORDER __BIG_ENDIAN -#elif defined(__MIPSEL__) -# define __BYTE_ORDER __LITTLE_ENDIAN -#else -# error "Neither __MIPSEB__ nor __MIPSEL__ defined" -#endif - -#endif /* _KLIBC_ENDIAN_H */ diff --git a/klibc/arch/parisc/include/klibc/endian.h b/klibc/arch/parisc/include/klibc/endian.h deleted file mode 100644 index d849f7227ebb3..0000000000000 --- a/klibc/arch/parisc/include/klibc/endian.h +++ /dev/null @@ -1,10 +0,0 @@ -/* - * arch/parisc/include/klibc/endian.h - */ - -#ifndef _KLIBC_ENDIAN_H -#define _KLIBC_ENDIAN_H - -#define __BYTE_ORDER __BIG_ENDIAN - -#endif /* _KLIBC_ENDIAN_H */ diff --git a/klibc/arch/ppc/include/klibc/endian.h b/klibc/arch/ppc/include/klibc/endian.h deleted file mode 100644 index ba42645519313..0000000000000 --- a/klibc/arch/ppc/include/klibc/endian.h +++ /dev/null @@ -1,10 +0,0 @@ -/* - * arch/ppc/include/klibc/endian.h - */ - -#ifndef _KLIBC_ENDIAN_H -#define _KLIBC_ENDIAN_H - -#define __BYTE_ORDER __BIG_ENDIAN - -#endif /* _KLIBC_ENDIAN_H */ diff --git a/klibc/arch/ppc64/include/klibc/endian.h b/klibc/arch/ppc64/include/klibc/endian.h deleted file mode 100644 index eb18078b25cfe..0000000000000 --- a/klibc/arch/ppc64/include/klibc/endian.h +++ /dev/null @@ -1,10 +0,0 @@ -/* - * arch/ppc64/include/klibc/endian.h - */ - -#ifndef _KLIBC_ENDIAN_H -#define _KLIBC_ENDIAN_H - -#define __BYTE_ORDER __BIG_ENDIAN - -#endif /* _KLIBC_ENDIAN_H */ diff --git a/klibc/arch/s390/include/klibc/endian.h b/klibc/arch/s390/include/klibc/endian.h deleted file mode 100644 index f30347a73531f..0000000000000 --- a/klibc/arch/s390/include/klibc/endian.h +++ /dev/null @@ -1,10 +0,0 @@ -/* - * arch/s390/include/klibc/endian.h - */ - -#ifndef _KLIBC_ENDIAN_H -#define _KLIBC_ENDIAN_H - -#define __BYTE_ORDER __BIG_ENDIAN - -#endif /* _KLIBC_ENDIAN_H */ diff --git a/klibc/arch/s390x/include/klibc/endian.h b/klibc/arch/s390x/include/klibc/endian.h deleted file mode 100644 index 87218fd94df80..0000000000000 --- a/klibc/arch/s390x/include/klibc/endian.h +++ /dev/null @@ -1,10 +0,0 @@ -/* - * arch/s390x/include/klibc/endian.h - */ - -#ifndef _KLIBC_ENDIAN_H -#define _KLIBC_ENDIAN_H - -#define __BYTE_ORDER __BIG_ENDIAN - -#endif /* _KLIBC_ENDIAN_H */ diff --git a/klibc/arch/sparc/include/klibc/endian.h b/klibc/arch/sparc/include/klibc/endian.h deleted file mode 100644 index 39c4897d3c7de..0000000000000 --- a/klibc/arch/sparc/include/klibc/endian.h +++ /dev/null @@ -1,10 +0,0 @@ -/* - * arch/sparc/include/klibc/endian.h - */ - -#ifndef _KLIBC_ENDIAN_H -#define _KLIBC_ENDIAN_H - -#define __BYTE_ORDER __BIG_ENDIAN - -#endif /* _KLIBC_ENDIAN_H */ diff --git a/klibc/arch/sparc64/include/klibc/endian.h b/klibc/arch/sparc64/include/klibc/endian.h deleted file mode 100644 index 5c099821cdb87..0000000000000 --- a/klibc/arch/sparc64/include/klibc/endian.h +++ /dev/null @@ -1,10 +0,0 @@ -/* - * arch/sparc64/include/klibc/endian.h - */ - -#ifndef _KLIBC_ENDIAN_H -#define _KLIBC_ENDIAN_H - -#define __BYTE_ORDER __BIG_ENDIAN - -#endif /* _KLIBC_ENDIAN_H */ diff --git a/klibc/include/endian.h b/klibc/include/endian.h index 7a3680dd11d40..348d659a4cce1 100644 --- a/klibc/include/endian.h +++ b/klibc/include/endian.h @@ -5,11 +5,33 @@ #ifndef _ENDIAN_H #define _ENDIAN_H -#define __LITTLE_ENDIAN 1234 -#define __BIG_ENDIAN 4321 -#define __PDP_ENDIAN 3412 +#include <asm/byteorder.h> -#include <klibc/endian.h> +/* Linux' asm/byteorder.h defines either __LITTLE_ENDIAN or __BIG_ENDIAN, + but the BSD-ish macros expect both to be defined with __BYTE_ORDER + defining which is actually used... */ + +#if defined(__LITTLE_ENDIAN) +# undef __LITTLE_ENDIAN +# define __LITTLE_ENDIAN 1234 +# define __BIG_ENDIAN 4321 +# define __PDP_ENDIAN 3412 +# define __BYTE_ORDER __LITTLE_ENDIAN +#elif defined(__BIG_ENDIAN) +# undef __BIG_ENDIAN +# define __LITTLE_ENDIAN 1234 +# define __BIG_ENDIAN 4321 +# define __PDP_ENDIAN 3412 +# define __BYTE_ORDER __BIG_ENDIAN +#elif defined(__PDP_ENDIAN) +# undef __PDP_ENDIAN +# define __LITTLE_ENDIAN 1234 +# define __BIG_ENDIAN 4321 +# define __PDP_ENDIAN 3412 +# define __BYTE_ORDER __PDP_ENDIAN +#else +# error "Unknown byte order!" +#endif #define LITTLE_ENDIAN __LITTLE_ENDIAN #define BIG_ENDIAN __BIG_ENDIAN diff --git a/klibc/include/netinet/in.h b/klibc/include/netinet/in.h index c1f1c164fd359..4b7e77ee7d188 100644 --- a/klibc/include/netinet/in.h +++ b/klibc/include/netinet/in.h @@ -8,38 +8,9 @@ #include <stdint.h> #include <endian.h> -#if __BYTE_ORDER == __BIG_ENDIAN - -#define htonl(x) ((uint32_t)(x)) -#define ntohl(x) ((uint32_t)(x)) -#define htons(x) ((uint16_t)(x)) -#define ntohs(x) ((uint16_t)(x)) - -#elif __BYTE_ORDER == __LITTLE_ENDIAN - -static __inline__ -uint32_t htonl(uint32_t __x) -{ -#if defined(__i486__)||defined(__pentium__)||defined(__pentiumpro__) - asm("bswap %0" : "+rm" (__x)); - return __x; -#else - return (__x >> 24) + ((__x >> 8) & 0xff00) + - ((__x & 0xff00) << 8) + (__x << 24); -#endif -} - -static __inline__ -uint16_t htons(uint16_t __x) -{ - return (__x >> 8) + (__x << 8); -} - -#define htonl(x) htonl(x) -#define ntohl(x) htohl(x) -#define htons(x) htons(x) -#define ntohs(x) htons(x) - -#endif /* endian */ +#define htons(x) __cpu_to_be16(x) +#define ntohs(x) __be16_to_cpu(x) +#define htonl(x) __cpu_to_be32(x) +#define ntohl(x) __be32_to_cpu(x) #endif /* _NETINET_IN_H */ |