summaryrefslogtreecommitdiff
path: root/lib/libc/rpc/xdr_mem.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/libc/rpc/xdr_mem.c')
-rw-r--r--lib/libc/rpc/xdr_mem.c88
1 files changed, 72 insertions, 16 deletions
diff --git a/lib/libc/rpc/xdr_mem.c b/lib/libc/rpc/xdr_mem.c
index 5927e8b330d..a1bbb866a4d 100644
--- a/lib/libc/rpc/xdr_mem.c
+++ b/lib/libc/rpc/xdr_mem.c
@@ -1,4 +1,5 @@
-/* $NetBSD: xdr_mem.c,v 1.3 1995/02/25 03:02:07 cgd Exp $ */
+/* $OpenBSD: xdr_mem.c,v 1.2 1996/03/09 02:42:53 niklas Exp $ */
+/* $NetBSD: xdr_mem.c,v 1.4 1996/02/08 08:06:05 mycroft Exp $ */
/*
* Sun RPC is a product of Sun Microsystems, Inc. and is provided for
@@ -32,7 +33,7 @@
#if defined(LIBC_SCCS) && !defined(lint)
/*static char *sccsid = "from: @(#)xdr_mem.c 1.19 87/08/11 Copyr 1984 Sun Micro";*/
/*static char *sccsid = "from: @(#)xdr_mem.c 2.1 88/07/29 4.0 RPCSRC";*/
-static char *rcsid = "$NetBSD: xdr_mem.c,v 1.3 1995/02/25 03:02:07 cgd Exp $";
+static char *rcsid = "$NetBSD: xdr_mem.c,v 1.4 1996/02/08 08:06:05 mycroft Exp $";
#endif
/*
@@ -51,23 +52,37 @@ static char *rcsid = "$NetBSD: xdr_mem.c,v 1.3 1995/02/25 03:02:07 cgd Exp $";
#include <rpc/xdr.h>
#include <netinet/in.h>
-static bool_t xdrmem_getlong();
-static bool_t xdrmem_putlong();
+static bool_t xdrmem_getlong_aligned();
+static bool_t xdrmem_putlong_aligned();
+static bool_t xdrmem_getlong_unaligned();
+static bool_t xdrmem_putlong_unaligned();
static bool_t xdrmem_getbytes();
static bool_t xdrmem_putbytes();
static u_int xdrmem_getpos(); /* XXX w/64-bit pointers, u_int not enough! */
static bool_t xdrmem_setpos();
-static int32_t *xdrmem_inline();
+static int32_t *xdrmem_inline_aligned();
+static int32_t *xdrmem_inline_unaligned();
static void xdrmem_destroy();
-static struct xdr_ops xdrmem_ops = {
- xdrmem_getlong,
- xdrmem_putlong,
+static struct xdr_ops xdrmem_ops_aligned = {
+ xdrmem_getlong_aligned,
+ xdrmem_putlong_aligned,
xdrmem_getbytes,
xdrmem_putbytes,
xdrmem_getpos,
xdrmem_setpos,
- xdrmem_inline,
+ xdrmem_inline_aligned,
+ xdrmem_destroy
+};
+
+static struct xdr_ops xdrmem_ops_unaligned = {
+ xdrmem_getlong_unaligned,
+ xdrmem_putlong_unaligned,
+ xdrmem_getbytes,
+ xdrmem_putbytes,
+ xdrmem_getpos,
+ xdrmem_setpos,
+ xdrmem_inline_unaligned,
xdrmem_destroy
};
@@ -84,7 +99,8 @@ xdrmem_create(xdrs, addr, size, op)
{
xdrs->x_op = op;
- xdrs->x_ops = &xdrmem_ops;
+ xdrs->x_ops = ((size_t)addr & (sizeof(int32_t) - 1))
+ ? &xdrmem_ops_unaligned : &xdrmem_ops_aligned;
xdrs->x_private = xdrs->x_base = addr;
xdrs->x_handy = size;
}
@@ -93,30 +109,61 @@ static void
xdrmem_destroy(/*xdrs*/)
/*XDR *xdrs;*/
{
+
+}
+
+static bool_t
+xdrmem_getlong_aligned(xdrs, lp)
+ register XDR *xdrs;
+ long *lp;
+{
+
+ if ((xdrs->x_handy -= sizeof(int32_t)) < 0)
+ return (FALSE);
+ *lp = ntohl(*(int32_t *)xdrs->x_private);
+ xdrs->x_private += sizeof(int32_t);
+ return (TRUE);
}
static bool_t
-xdrmem_getlong(xdrs, lp)
+xdrmem_putlong_aligned(xdrs, lp)
register XDR *xdrs;
long *lp;
{
if ((xdrs->x_handy -= sizeof(int32_t)) < 0)
return (FALSE);
- *lp = (long)ntohl((u_int32_t)(*((int32_t *)(xdrs->x_private))));
+ *(int32_t *)xdrs->x_private = htonl(*lp);
xdrs->x_private += sizeof(int32_t);
return (TRUE);
}
static bool_t
-xdrmem_putlong(xdrs, lp)
+xdrmem_getlong_unaligned(xdrs, lp)
register XDR *xdrs;
long *lp;
{
+ int32_t l;
if ((xdrs->x_handy -= sizeof(int32_t)) < 0)
return (FALSE);
- *(int32_t *)xdrs->x_private = (int32_t)htonl((int32_t)(*lp));
+ bcopy(xdrs->x_private, &l, sizeof(int32_t));
+ *lp = ntohl(l);
+ xdrs->x_private += sizeof(int32_t);
+ return (TRUE);
+}
+
+static bool_t
+xdrmem_putlong_unaligned(xdrs, lp)
+ register XDR *xdrs;
+ long *lp;
+{
+ int32_t l;
+
+ if ((xdrs->x_handy -= sizeof(int32_t)) < 0)
+ return (FALSE);
+ l = htonl(*lp);
+ bcopy(&l, xdrs->x_private, sizeof(int32_t));
xdrs->x_private += sizeof(int32_t);
return (TRUE);
}
@@ -174,7 +221,7 @@ xdrmem_setpos(xdrs, pos)
}
static int32_t *
-xdrmem_inline(xdrs, len)
+xdrmem_inline_aligned(xdrs, len)
register XDR *xdrs;
int len;
{
@@ -182,8 +229,17 @@ xdrmem_inline(xdrs, len)
if (xdrs->x_handy >= len) {
xdrs->x_handy -= len;
- buf = (int32_t *) xdrs->x_private;
+ buf = (int32_t *)xdrs->x_private;
xdrs->x_private += len;
}
return (buf);
}
+
+static int32_t *
+xdrmem_inline_unaligned(xdrs, len)
+ register XDR *xdrs;
+ int len;
+{
+
+ return (0);
+}