diff options
author | 1995-10-18 08:37:01 +0000 | |
---|---|---|
committer | 1995-10-18 08:37:01 +0000 | |
commit | df930be708d50e9715f173caa26ffe1b7599b157 (patch) | |
tree | aa317e49e28cb999c9cf3db7f00c20903fe6010a /sys/lib/libkern/htons.c | |
download | wireguard-openbsd-df930be708d50e9715f173caa26ffe1b7599b157.tar.xz wireguard-openbsd-df930be708d50e9715f173caa26ffe1b7599b157.zip |
initial import of NetBSD tree
Diffstat (limited to 'sys/lib/libkern/htons.c')
-rw-r--r-- | sys/lib/libkern/htons.c | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/sys/lib/libkern/htons.c b/sys/lib/libkern/htons.c new file mode 100644 index 00000000000..6d491588b59 --- /dev/null +++ b/sys/lib/libkern/htons.c @@ -0,0 +1,27 @@ +/* $NetBSD: htons.c,v 1.6 1995/10/07 09:26:27 mycroft Exp $ */ + +/* + * Written by J.T. Conklin <jtc@netbsd.org>. + * Public domain. + */ + +#if defined(LIBC_SCCS) && !defined(lint) +static char *rcsid = "$NetBSD: htons.c,v 1.6 1995/10/07 09:26:27 mycroft Exp $"; +#endif + +#include <sys/types.h> +#include <machine/endian.h> + +#undef htons + +unsigned short +htons(x) + unsigned short x; +{ +#if BYTE_ORDER == LITTLE_ENDIAN + u_char *s = (u_char *) &x; + return s[0] << 8 | s[1]; +#else + return x; +#endif +} |