add bigendian support
[unix-history] / usr / src / lib / libc / mips / net / htons.s
index a63ea54..f330466 100644 (file)
 #include "DEFS.h"
 
 #if defined(LIBC_SCCS) && !defined(lint)
 #include "DEFS.h"
 
 #if defined(LIBC_SCCS) && !defined(lint)
-       ASMSTR("@(#)htons.s     5.2 (Berkeley) %G%")
+       ASMSTR("@(#)htons.s     5.3 (Berkeley) %G%")
 #endif /* LIBC_SCCS and not lint */
 
 #endif /* LIBC_SCCS and not lint */
 
+#include <machine/endian.h>
+#undef htons
+#undef ntohs
+
 /*
  * netorder = htons(hostorder)
  * hostorder = ntohs(netorder)
  */
 LEAF(htons)
 ALEAF(ntohs)
 /*
  * netorder = htons(hostorder)
  * hostorder = ntohs(netorder)
  */
 LEAF(htons)
 ALEAF(ntohs)
+#if BYTE_ORDER == LITTLE_ENDIAN
        srl     v0, a0, 8
        and     v0, v0, 0xff
        sll     v1, a0, 8
        and     v1, v1, 0xff00
        or      v0, v0, v1
        srl     v0, a0, 8
        and     v0, v0, 0xff
        sll     v1, a0, 8
        and     v1, v1, 0xff00
        or      v0, v0, v1
+#else
+#if BYTE_ORDER == BIG_ENDIAN
+       move    v0, a0
+#else
+       ERROR
+#endif
+#endif
        j       ra
 END(htons)
        j       ra
 END(htons)