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
31 * xdr_mem.h, XDR implementation using memory buffers.
33 * Copyright (C) 1984, Sun Microsystems, Inc.
35 * If you have some data to be interpreted as external data representation
36 * or to be converted to external data representation in a memory buffer,
37 * then this is the package for you.
47 static bool_t xdrmem_getlong (XDR *, long *);
48 static bool_t xdrmem_putlong (XDR *, const long *);
49 static bool_t xdrmem_getbytes (XDR *, caddr_t, u_int);
50 static bool_t xdrmem_putbytes (XDR *, const char *, u_int);
51 static u_int xdrmem_getpos (const XDR *);
52 static bool_t xdrmem_setpos (XDR *, u_int);
53 static int32_t *xdrmem_inline (XDR *, u_int);
54 static void xdrmem_destroy (XDR *);
55 static bool_t xdrmem_getint32 (XDR *, int32_t *);
56 static bool_t xdrmem_putint32 (XDR *, const int32_t *);
58 static const struct xdr_ops xdrmem_ops =
73 * The procedure xdrmem_create initializes a stream descriptor for a
77 xdrmem_create (XDR *xdrs, const caddr_t addr, u_int size, enum xdr_op op)
80 /* We have to add the const since the `struct xdr_ops' in `struct XDR'
82 xdrs->x_ops = (struct xdr_ops *) &xdrmem_ops;
83 xdrs->x_private = xdrs->x_base = addr;
86 libc_hidden_def(xdrmem_create)
89 * Nothing needs to be done for the memory case. The argument is clearly
94 xdrmem_destroy (XDR *xdrs attribute_unused)
99 * Gets the next word from the memory referenced by xdrs and places it
100 * in the long pointed to by lp. It then increments the private word to
101 * point at the next element. Neither object pointed to is const
104 xdrmem_getlong (XDR *xdrs, long *lp)
106 if (xdrs->x_handy < 4)
109 *lp = (int32_t) ntohl ((*((int32_t *) (xdrs->x_private))));
110 xdrs->x_private += 4;
115 * Puts the long pointed to by lp in the memory referenced by xdrs. It
116 * then increments the private word to point at the next element. The
117 * long pointed at is const
120 xdrmem_putlong (XDR *xdrs, const long *lp)
122 if (xdrs->x_handy < 4)
125 *(int32_t *) xdrs->x_private = htonl (*lp);
126 xdrs->x_private += 4;
131 * Gets an unaligned number of bytes from the xdrs structure and writes them
132 * to the address passed in addr. Be very careful when calling this routine
133 * as it could leave the xdrs pointing to an unaligned structure which is not
134 * a good idea. None of the things pointed to are const.
137 xdrmem_getbytes (XDR *xdrs, caddr_t addr, u_int len)
139 if (xdrs->x_handy < len)
141 xdrs->x_handy -= len;
142 memcpy (addr, xdrs->x_private, len);
143 xdrs->x_private += len;
148 * The complementary function to the above. The same warnings apply about
149 * unaligned data. The source address is const.
152 xdrmem_putbytes (XDR *xdrs, const char *addr, u_int len)
154 if (xdrs->x_handy < len)
156 xdrs->x_handy -= len;
157 memcpy (xdrs->x_private, addr, len);
158 xdrs->x_private += len;
163 * Not sure what this one does. But it clearly doesn't modify the contents
164 * of xdrs. **FIXME** does this not assume u_int == u_long?
167 xdrmem_getpos (const XDR *xdrs)
169 return (u_long) xdrs->x_private - (u_long) xdrs->x_base;
176 xdrmem_setpos (XDR *xdrs, u_int pos)
178 caddr_t newaddr = xdrs->x_base + pos;
179 caddr_t lastaddr = xdrs->x_private + xdrs->x_handy;
181 if ((long) newaddr > (long) lastaddr
182 || (UINT_MAX < LONG_MAX
183 && (long) UINT_MAX < (long) lastaddr - (long) newaddr))
185 xdrs->x_private = newaddr;
186 xdrs->x_handy = (long) lastaddr - (long) newaddr;
194 xdrmem_inline (XDR *xdrs, u_int len)
198 if (xdrs->x_handy >= len)
200 xdrs->x_handy -= len;
201 buf = (int32_t *) xdrs->x_private;
202 xdrs->x_private += len;
208 * Gets the next word from the memory referenced by xdrs and places it
209 * in the int pointed to by ip. It then increments the private word to
210 * point at the next element. Neither object pointed to is const
213 xdrmem_getint32 (XDR *xdrs, int32_t *ip)
215 if (xdrs->x_handy < 4)
218 *ip = ntohl ((*((int32_t *) (xdrs->x_private))));
219 xdrs->x_private += 4;
224 * Puts the long pointed to by lp in the memory referenced by xdrs. It
225 * then increments the private word to point at the next element. The
226 * long pointed at is const
229 xdrmem_putint32 (XDR *xdrs, const int32_t *ip)
231 if (xdrs->x_handy < 4)
234 *(int32_t *) xdrs->x_private = htonl (*ip);
235 xdrs->x_private += 4;