diff options
Diffstat (limited to 'src/lib/libc/net/htonl.c')
| -rw-r--r-- | src/lib/libc/net/htonl.c | 19 | 
1 files changed, 7 insertions, 12 deletions
diff --git a/src/lib/libc/net/htonl.c b/src/lib/libc/net/htonl.c index ac85cb0fd7..f104e190a2 100644 --- a/src/lib/libc/net/htonl.c +++ b/src/lib/libc/net/htonl.c  | |||
| @@ -1,29 +1,24 @@ | |||
| 1 | /* $NetBSD: htonl.c,v 1.5 1995/04/28 23:25:14 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) | 
| 9 | static char *rcsid = "$NetBSD: htonl.c,v 1.5 1995/04/28 23:25:14 jtc Exp $"; | 7 | static char *rcsid = "$OpenBSD: htonl.c,v 1.5 2005/03/25 13:24:12 otto 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 htonl | 13 | #undef htonl | 
| 16 | 14 | ||
| 17 | unsigned long | 15 | u_int32_t | 
| 18 | htonl(x) | 16 | htonl(u_int32_t x) | 
| 19 | unsigned long x; | ||
| 20 | { | 17 | { | 
| 21 | u_int32_t y = x; | ||
| 22 | |||
| 23 | #if BYTE_ORDER == LITTLE_ENDIAN | 18 | #if BYTE_ORDER == LITTLE_ENDIAN | 
| 24 | u_char *s = (u_char *)&y; | 19 | u_char *s = (u_char *)&x; | 
| 25 | return s[0] << 24 | s[1] << 16 | s[2] << 8 | s[3]; | 20 | return (u_int32_t)(s[0] << 24 | s[1] << 16 | s[2] << 8 | s[3]); | 
| 26 | #else | 21 | #else | 
| 27 | return y; | 22 | return x; | 
| 28 | #endif | 23 | #endif | 
| 29 | } | 24 | } | 
