summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter S. Mazinger <ps.m@gmx.net>2011-03-17 00:39:55 +0100
committerBernhard Reutner-Fischer <rep.dot.nop@gmail.com>2012-06-15 14:00:26 +0200
commit29ad443b375ccaa778d43b29efb99bd43a877908 (patch)
tree481ca6eab4cd1c86e65618720b8599f8ec97502e
parent6d0a357bd0339fae99a17285ab13b021b52449d8 (diff)
ntohl.c: simplify and shrink ntohl and friends
Signed-off-by: Peter S. Mazinger <ps.m@gmx.net> Signed-off-by: Bernhard Reutner-Fischer <rep.dot.nop@gmail.com>
-rw-r--r--libc/inet/ntohl.c54
1 files 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 <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)