summaryrefslogtreecommitdiff
path: root/src/lib/libc/net/htons.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libc/net/htons.c')
-rw-r--r--src/lib/libc/net/htons.c13
1 files changed, 5 insertions, 8 deletions
diff --git a/src/lib/libc/net/htons.c b/src/lib/libc/net/htons.c
index b2500a51d1..ded70712ea 100644
--- a/src/lib/libc/net/htons.c
+++ b/src/lib/libc/net/htons.c
@@ -1,26 +1,23 @@
1/* $NetBSD: htons.c,v 1.5 1995/04/28 23:25:19 jtc Exp $ */
2
3/* 1/*
4 * Written by J.T. Conklin <jtc@netbsd.org>. 2 * Written by J.T. Conklin <jtc@netbsd.org>.
5 * Public domain. 3 * Public domain.
6 */ 4 */
7 5
8#if defined(LIBC_SCCS) && !defined(lint) 6#if defined(LIBC_SCCS) && !defined(lint)
9static char *rcsid = "$NetBSD: htons.c,v 1.5 1995/04/28 23:25:19 jtc Exp $"; 7static char *rcsid = "$OpenBSD: htons.c,v 1.7 2002/02/19 19:39:36 millert Exp $";
10#endif 8#endif /* LIBC_SCCS and not lint */
11 9
12#include <sys/types.h> 10#include <sys/types.h>
13#include <machine/endian.h> 11#include <machine/endian.h>
14 12
15#undef htons 13#undef htons
16 14
17unsigned short 15u_int16_t
18htons(x) 16htons(u_int16_t x)
19 unsigned short x;
20{ 17{
21#if BYTE_ORDER == LITTLE_ENDIAN 18#if BYTE_ORDER == LITTLE_ENDIAN
22 u_char *s = (u_char *) &x; 19 u_char *s = (u_char *) &x;
23 return s[0] << 8 | s[1]; 20 return (u_int16_t)(s[0] << 8 | s[1]);
24#else 21#else
25 return x; 22 return x;
26#endif 23#endif