diff options
Diffstat (limited to 'src/lib/libc/net/htonl.c')
-rw-r--r-- | src/lib/libc/net/htonl.c | 20 |
1 files changed, 6 insertions, 14 deletions
diff --git a/src/lib/libc/net/htonl.c b/src/lib/libc/net/htonl.c index ac85cb0fd7..5ab4189597 100644 --- a/src/lib/libc/net/htonl.c +++ b/src/lib/libc/net/htonl.c | |||
@@ -1,29 +1,21 @@ | |||
1 | /* $NetBSD: htonl.c,v 1.5 1995/04/28 23:25:14 jtc Exp $ */ | 1 | /* $OpenBSD: htonl.c,v 1.6 2005/08/06 20:30:03 espie Exp $ */ |
2 | |||
3 | /* | 2 | /* |
4 | * Written by J.T. Conklin <jtc@netbsd.org>. | 3 | * Written by J.T. Conklin <jtc@netbsd.org>. |
5 | * Public domain. | 4 | * Public domain. |
6 | */ | 5 | */ |
7 | 6 | ||
8 | #if defined(LIBC_SCCS) && !defined(lint) | ||
9 | static char *rcsid = "$NetBSD: htonl.c,v 1.5 1995/04/28 23:25:14 jtc Exp $"; | ||
10 | #endif | ||
11 | |||
12 | #include <sys/types.h> | 7 | #include <sys/types.h> |
13 | #include <machine/endian.h> | 8 | #include <machine/endian.h> |
14 | 9 | ||
15 | #undef htonl | 10 | #undef htonl |
16 | 11 | ||
17 | unsigned long | 12 | u_int32_t |
18 | htonl(x) | 13 | htonl(u_int32_t x) |
19 | unsigned long x; | ||
20 | { | 14 | { |
21 | u_int32_t y = x; | ||
22 | |||
23 | #if BYTE_ORDER == LITTLE_ENDIAN | 15 | #if BYTE_ORDER == LITTLE_ENDIAN |
24 | u_char *s = (u_char *)&y; | 16 | u_char *s = (u_char *)&x; |
25 | return s[0] << 24 | s[1] << 16 | s[2] << 8 | s[3]; | 17 | return (u_int32_t)(s[0] << 24 | s[1] << 16 | s[2] << 8 | s[3]); |
26 | #else | 18 | #else |
27 | return y; | 19 | return x; |
28 | #endif | 20 | #endif |
29 | } | 21 | } |