summaryrefslogtreecommitdiffstats
path: root/lib/libc/arch/sh/net/ntohl.c
diff options
context:
space:
mode:
authormiod <miod@openbsd.org>2006-10-10 22:07:10 +0000
committermiod <miod@openbsd.org>2006-10-10 22:07:10 +0000
commitcf2525843d483a385de106a1361b2b9c18d96583 (patch)
tree266292ca5f95ab885e1c3fc36ac3c6b75335be17 /lib/libc/arch/sh/net/ntohl.c
parentTeach'em about cpus in spandex (diff)
downloadwireguard-openbsd-cf2525843d483a385de106a1361b2b9c18d96583.tar.xz
wireguard-openbsd-cf2525843d483a385de106a1361b2b9c18d96583.zip
Preliminary userland bits for OpenBSD/landisk, many things coming from
NetBSD.
Diffstat (limited to 'lib/libc/arch/sh/net/ntohl.c')
-rw-r--r--lib/libc/arch/sh/net/ntohl.c58
1 files changed, 58 insertions, 0 deletions
diff --git a/lib/libc/arch/sh/net/ntohl.c b/lib/libc/arch/sh/net/ntohl.c
new file mode 100644
index 00000000000..427fd3ae95f
--- /dev/null
+++ b/lib/libc/arch/sh/net/ntohl.c
@@ -0,0 +1,58 @@
+/* $OpenBSD: ntohl.c,v 1.1.1.1 2006/10/10 22:07:10 miod Exp $ */
+/* $NetBSD: ntohl.c,v 1.3 2005/12/24 23:10:08 perry Exp $ */
+
+/*-
+ * Copyright (c) 1990 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to Berkeley by
+ * William Jolitz.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the University nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * from: @(#)ntohl.s 5.2 (Berkeley) 12/17/90
+ */
+
+#include <sys/types.h>
+#include <machine/endian.h>
+
+#undef ntohl
+
+/* netorder = ntohl(hostorder) */
+u_int32_t
+ntohl(x)
+ u_int32_t x;
+{
+#if BYTE_ORDER == LITTLE_ENDIAN
+ u_int32_t y = 0;
+
+ __asm("swap.b %1, %0" : "=r" (y) : "r" (x));
+ __asm("swap.w %1, %0" : "=r" (y) : "r" (y));
+ __asm("swap.b %1, %0" : "=r" (y) : "r" (y));
+ return y;
+#else
+ return x;
+#endif
+}