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