[git commit] ntohl.c: simplify and shrink ntohl and friends

Bernhard Reutner-Fischer rep.dot.nop at gmail.com
Fri Jun 15 12:00:26 UTC 2012


commit: http://git.uclibc.org/uClibc/commit/?id=29ad443b375ccaa778d43b29efb99bd43a877908
branch: http://git.uclibc.org/uClibc/commit/?id=refs/heads/master

Signed-off-by: Peter S. Mazinger <ps.m at gmx.net>
Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop at gmail.com>
---
 libc/inet/ntohl.c |   54 ++++++++++++++--------------------------------------
 1 files changed, 15 insertions(+), 39 deletions(-)

diff --git a/libc/inet/ntohl.c b/libc/inet/ntohl.c
index 1a58632..8e500a5 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 <stdint.h>
-#include <endian.h>
-#include <byteswap.h>
 #include <netinet/in.h>
 
 #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)


More information about the uClibc-cvs mailing list