2 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
3 * unrestricted use provided that this legend is included on all tape
4 * media and as a part of the software program in whole or part. Users
5 * may copy or modify Sun RPC without charge, but are not authorized
6 * to license or distribute it to anyone else except as part of a product or
7 * program developed by the user.
9 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
10 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
11 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
13 * Sun RPC is provided with no support and without any obligation on the
14 * part of Sun Microsystems, Inc. to assist in its use, correction,
15 * modification or enhancement.
17 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
18 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
19 * OR ANY PART THEREOF.
21 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
22 * or profits or other special, indirect and consequential damages, even if
23 * Sun has been advised of the possibility of such damages.
25 * Sun Microsystems, Inc.
27 * Mountain View, California 94043
29 #include <afsconfig.h>
30 #include <afs/param.h>
33 * xdr_mem.h, XDR implementation using memory buffers.
35 * Copyright (C) 1984, Sun Microsystems, Inc.
37 * If you have some data to be interpreted as external data representation
38 * or to be converted to external data representation in a memory buffer,
39 * then this is the package for you.
44 # include "afs/sysincludes.h"
52 static bool_t
xdrmem_getint32(XDR
*, afs_int32
*);
53 static bool_t
xdrmem_putint32(XDR
*, afs_int32
*);
54 static bool_t
xdrmem_getbytes(XDR
*, caddr_t
, u_int
);
55 static bool_t
xdrmem_putbytes(XDR
*, caddr_t
, u_int
);
56 static u_int
xdrmem_getpos(XDR
*);
57 static bool_t
xdrmem_setpos(XDR
*, u_int
);
58 static afs_int32
*xdrmem_inline(XDR
*, u_int
);
59 static void xdrmem_destroy(XDR
*);
61 static struct xdr_ops xdrmem_ops
= {
62 #ifndef HAVE_STRUCT_LABEL_SUPPORT
63 /* Windows does not support labeled assigments */
64 xdrmem_getint32
, /* deserialize an afs_int32 */
65 xdrmem_putint32
, /* serialize an afs_int32 */
66 xdrmem_getbytes
, /* deserialize counted bytes */
67 xdrmem_putbytes
, /* serialize counted bytes */
68 xdrmem_getpos
, /* get offset in the stream: not supported. */
69 xdrmem_setpos
, /* set offset in the stream: not supported. */
70 xdrmem_inline
, /* prime stream for inline macros */
71 xdrmem_destroy
, /* destroy stream */
73 .x_getint32
= xdrmem_getint32
,
74 .x_putint32
= xdrmem_putint32
,
75 .x_getbytes
= xdrmem_getbytes
,
76 .x_putbytes
= xdrmem_putbytes
,
77 .x_getpostn
= xdrmem_getpos
,
78 .x_setpostn
= xdrmem_setpos
,
79 .x_inline
= xdrmem_inline
,
80 .x_destroy
= xdrmem_destroy
85 * The procedure xdrmem_create initializes a stream descriptor for a
89 xdrmem_create(XDR
* xdrs
, caddr_t addr
, u_int size
, enum xdr_op op
)
92 xdrs
->x_ops
= &xdrmem_ops
;
93 xdrs
->x_private
= xdrs
->x_base
= addr
;
94 xdrs
->x_handy
= (size
> INT_MAX
) ? INT_MAX
: size
; /* XXX */
98 xdrmem_destroy(XDR
*xdrs
)
103 xdrmem_getint32(XDR
*xdrs
, afs_int32
* lp
)
105 if (xdrs
->x_handy
< sizeof(afs_int32
))
108 xdrs
->x_handy
-= sizeof(afs_int32
);
109 *lp
= ntohl(*((afs_int32
*) (xdrs
->x_private
)));
110 xdrs
->x_private
+= sizeof(afs_int32
);
115 xdrmem_putint32(XDR
*xdrs
, afs_int32
* lp
)
117 if (xdrs
->x_handy
< sizeof(afs_int32
))
120 xdrs
->x_handy
-= sizeof(afs_int32
);
121 *(afs_int32
*) xdrs
->x_private
= htonl(*lp
);
122 xdrs
->x_private
+= sizeof(afs_int32
);
127 xdrmem_getbytes(XDR
*xdrs
, caddr_t addr
, u_int len
)
129 if (xdrs
->x_handy
< len
)
132 xdrs
->x_handy
-= len
;
133 memcpy(addr
, xdrs
->x_private
, len
);
134 xdrs
->x_private
+= len
;
139 xdrmem_putbytes(XDR
*xdrs
, caddr_t addr
, u_int len
)
141 if (xdrs
->x_handy
< len
)
144 xdrs
->x_handy
-= len
;
145 memcpy(xdrs
->x_private
, addr
, len
);
146 xdrs
->x_private
+= len
;
151 xdrmem_getpos(XDR
*xdrs
)
153 return ((u_int
)(xdrs
->x_private
- xdrs
->x_base
));
157 xdrmem_setpos(XDR
*xdrs
, u_int pos
)
159 caddr_t newaddr
= xdrs
->x_base
+ pos
;
160 caddr_t lastaddr
= xdrs
->x_private
+ xdrs
->x_handy
;
162 if (newaddr
> lastaddr
)
164 xdrs
->x_private
= newaddr
;
165 xdrs
->x_handy
= (int)(lastaddr
- newaddr
);
170 xdrmem_inline(XDR
*xdrs
, u_int len
)
174 if (xdrs
->x_handy
>= len
) {
175 xdrs
->x_handy
-= len
;
176 buf
= (afs_int32
*) xdrs
->x_private
;
177 xdrs
->x_private
+= len
;