From 29ad443b375ccaa778d43b29efb99bd43a877908 Mon Sep 17 00:00:00 2001 From: "Peter S. Mazinger" Date: Thu, 17 Mar 2011 00:39:55 +0100 Subject: ntohl.c: simplify and shrink ntohl and friends Signed-off-by: Peter S. Mazinger Signed-off-by: Bernhard Reutner-Fischer --- libc/inet/ntohl.c | 54 +++++++++++++++--------------------------------------- 1 file changed, 15 insertions(+), 39 deletions(-) diff --git a/libc/inet/ntohl.c b/libc/inet/ntohl.c index 1a5863286..8e500a5e3 100644 --- a/libc/inet/ntohl.c +++ b/libc/inet/ntohl.c @@ -6,9 +6,6 @@ * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball. */ -#include -#include -#include #include #undef ntohl @@ -16,51 +13,30 @@ #undef htonl #undef htons -#if __BYTE_ORDER == __BIG_ENDIAN -uint32_t ntohl (uint32_t x) -{ - return x; -} - -uint16_t ntohs (uint16_t x) -{ - return x; -} - -uint32_t htonl (uint32_t x) -{ - return x; -} +#if __BYTE_ORDER != __BIG_ENDIAN && __BYTE_ORDER != __LITTLE_ENDIAN +# error "You seem to have an unsupported byteorder" +#endif -uint16_t htons (uint16_t x) -{ - return x; -} -#elif __BYTE_ORDER == __LITTLE_ENDIAN uint32_t ntohl (uint32_t x) { +#if __BYTE_ORDER == __BIG_ENDIAN + return x; +#else return __bswap_32(x); +#endif } +libc_hidden_def(ntohl) +strong_alias(ntohl,htonl) +libc_hidden_def(htonl) uint16_t ntohs (uint16_t x) { - return __bswap_16(x); -} - -uint32_t htonl (uint32_t x) -{ - return __bswap_32(x); -} - -uint16_t htons (uint16_t x) -{ - return __bswap_16(x); -} +#if __BYTE_ORDER == __BIG_ENDIAN + return x; #else -#error "You seem to have an unsupported byteorder" + return __bswap_16(x); #endif - -libc_hidden_def(ntohl) +} libc_hidden_def(ntohs) -libc_hidden_def(htonl) +strong_alias(ntohs,htons) libc_hidden_def(htons) -- cgit v1.2.3