about summary refs log tree commit diff
path: root/sysdeps/generic/htons.c
diff options
context:
space:
mode:
Diffstat (limited to 'sysdeps/generic/htons.c')
-rw-r--r--sysdeps/generic/htons.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/sysdeps/generic/htons.c b/sysdeps/generic/htons.c
index a0a0e81adf..8914f74f2e 100644
--- a/sysdeps/generic/htons.c
+++ b/sysdeps/generic/htons.c
@@ -19,17 +19,18 @@
 #include <netinet/in.h>
 
 #undef	htons
+#undef	ntohs
 
 u_int16_t
 __htons (x)
      u_int16_t x;
 {
-#if BYTE_ORDER == LITTLE_ENDIAN
-  x = (x << 8) | (x >> 8);
-#endif
-
+#if BYTE_ORDER == BIG_ENDIAN
   return x;
+#elif BYTE_ORDER == LITTLE_ENDIAN
+  return __bswap_16 (x);
+#else
+# error "What kind of system is this?"
+#endif
 }
-strong_alias (__htons, __ntohs)
-weak_alias (__htons, htons)
-weak_alias (__ntohs, ntohs)
+weak_alias (htons, ntohs)