summaryrefslogtreecommitdiff
path: root/src/lib/libc/net/htons.c
diff options
context:
space:
mode:
authorcvs2svn <admin@example.com>1999-03-26 18:24:03 +0000
committercvs2svn <admin@example.com>1999-03-26 18:24:03 +0000
commit3fc228fb4c1a39aceaee3d7013365042a6077bd0 (patch)
treeaf769f6648929b3b2c1f9e053a3754fa989ce302 /src/lib/libc/net/htons.c
parent536c76cbb863bab152f19842ab88772c01e922c7 (diff)
downloadopenbsd-OPENBSD_2_5.tar.gz
openbsd-OPENBSD_2_5.tar.bz2
openbsd-OPENBSD_2_5.zip
This commit was manufactured by cvs2git to create branch 'OPENBSD_2_5'.OPENBSD_2_5
Diffstat (limited to 'src/lib/libc/net/htons.c')
-rw-r--r--src/lib/libc/net/htons.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/lib/libc/net/htons.c b/src/lib/libc/net/htons.c
new file mode 100644
index 0000000000..47cf25952d
--- /dev/null
+++ b/src/lib/libc/net/htons.c
@@ -0,0 +1,29 @@
1/*
2 * Written by J.T. Conklin <jtc@netbsd.org>.
3 * Public domain.
4 */
5
6#if defined(LIBC_SCCS) && !defined(lint)
7static char *rcsid = "$OpenBSD: htons.c,v 1.6 1997/07/25 20:30:07 mickey Exp $";
8#endif /* LIBC_SCCS and not lint */
9
10#include <sys/types.h>
11#include <machine/endian.h>
12
13#undef htons
14
15u_int16_t
16#ifdef __STDC__
17htons(u_int16_t x)
18#else
19htons(x)
20 u_int16_t x;
21#endif
22{
23#if BYTE_ORDER == LITTLE_ENDIAN
24 u_char *s = (u_char *) &x;
25 return (u_int16_t)(s[0] << 8 | s[1]);
26#else
27 return x;
28#endif
29}