source: rtems-libbsd/services/librpc/src/xdr/xdr_mem.c @ cd450d2

4.1155-freebsd-126-freebsd-12freebsd-9.3
Last change on this file since cd450d2 was cd450d2, checked in by Joel Sherrill <joel.sherrill@…>, on 08/06/12 at 00:10:35

librpc: now compiles

  • Property mode set to 100644
File size: 5.6 KB
Line 
1/*
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.
8 *
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.
12 *
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.
16 *
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.
20 *
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.
24 *
25 * Sun Microsystems, Inc.
26 * 2550 Garcia Avenue
27 * Mountain View, California  94043
28 */
29
30#if defined(LIBC_SCCS) && !defined(lint)
31/*static char *sccsid = "from: @(#)xdr_mem.c 1.19 87/08/11 Copyr 1984 Sun Micro";*/
32/*static char *sccsid = "from: @(#)xdr_mem.c    2.1 88/07/29 4.0 RPCSRC";*/
33static char *rcsid = "$FreeBSD: src/lib/libc/xdr/xdr_mem.c,v 1.8 1999/08/28 00:02:56 peter Exp $";
34#endif
35
36/*
37 * xdr_mem.h, XDR implementation using memory buffers.
38 *
39 * Copyright (C) 1984, Sun Microsystems, Inc.
40 *
41 * If you have some data to be interpreted as external data representation
42 * or to be converted to external data representation in a memory buffer,
43 * then this is the package for you.
44 *
45 */
46
47#ifdef HAVE_CONFIG_H
48#include "config.h"
49#endif
50
51#include <freebsd/bsd.h>
52#include <string.h>
53#include <rpc/types.h>
54#include <rpc/xdr.h>
55#include <netinet/in.h>
56
57static bool_t   xdrmem_getlong_aligned(XDR *xdrs, long *lp);
58static bool_t   xdrmem_putlong_aligned(XDR *xdrs, const long *lp);
59static bool_t   xdrmem_getlong_unaligned(XDR *xdrs, long *lp);
60static bool_t   xdrmem_putlong_unaligned(XDR *xdrs, const long *lp);
61static bool_t   xdrmem_getbytes(XDR *xdrs, caddr_t addr, u_int len);
62static bool_t   xdrmem_putbytes(XDR *xdrs, const char *addr, u_int len);
63static u_int    xdrmem_getpos(XDR *xdrs); /* XXX w/64-bit pointers, u_int not enough! */
64static bool_t   xdrmem_setpos(XDR *xdrs, u_int pos);
65static int32_t *xdrmem_inline_aligned(XDR *xdrs, u_int len);
66static int32_t *xdrmem_inline_unaligned(XDR *xdrs, u_int len);
67static void     xdrmem_destroy(XDR *);
68
69static struct   xdr_ops xdrmem_ops_aligned = {
70        xdrmem_getlong_aligned,
71        xdrmem_putlong_aligned,
72        xdrmem_getbytes,
73        xdrmem_putbytes,
74        xdrmem_getpos,
75        xdrmem_setpos,
76        xdrmem_inline_aligned,
77        xdrmem_destroy
78};
79
80static struct   xdr_ops xdrmem_ops_unaligned = {
81        xdrmem_getlong_unaligned,
82        xdrmem_putlong_unaligned,
83        xdrmem_getbytes,
84        xdrmem_putbytes,
85        xdrmem_getpos,
86        xdrmem_setpos,
87        xdrmem_inline_unaligned,
88        xdrmem_destroy
89};
90
91/*
92 * The procedure xdrmem_create initializes a stream descriptor for a
93 * memory buffer.
94 */
95void
96xdrmem_create(
97        XDR *xdrs,
98        char * addr,
99        u_int size,
100        enum xdr_op op)
101{
102
103        xdrs->x_op = op;
104        xdrs->x_ops = ((uintptr_t)addr & (sizeof(int32_t) - 1))
105                ? &xdrmem_ops_unaligned : &xdrmem_ops_aligned;
106        xdrs->x_private = xdrs->x_base = addr;
107        xdrs->x_handy = size;
108}
109
110static void
111xdrmem_destroy(XDR *xdrs)
112{
113
114}
115
116static bool_t
117xdrmem_getlong_aligned(
118        XDR *xdrs,
119        long *lp)
120{
121
122        if ((xdrs->x_handy -= sizeof(int32_t)) < 0)
123                return (FALSE);
124        *lp = ntohl(*(int32_t *)(xdrs->x_private));
125        xdrs->x_private += sizeof(int32_t);
126        return (TRUE);
127}
128
129static bool_t
130xdrmem_putlong_aligned(
131        XDR *xdrs,
132        const long *lp)
133{
134
135        if ((xdrs->x_handy -= sizeof(int32_t)) < 0)
136                return (FALSE);
137        *(int32_t *)xdrs->x_private = htonl(*lp);
138        xdrs->x_private += sizeof(int32_t);
139        return (TRUE);
140}
141
142static bool_t
143xdrmem_getlong_unaligned(
144        XDR *xdrs,
145        long *lp)
146{
147        int32_t l;
148
149        if ((xdrs->x_handy -= sizeof(int32_t)) < 0)
150                return (FALSE);
151        memcpy(&l, xdrs->x_private, sizeof(int32_t));
152        *lp = ntohl(l);
153        xdrs->x_private += sizeof(int32_t);
154        return (TRUE);
155}
156
157static bool_t
158xdrmem_putlong_unaligned(
159        XDR *xdrs,
160        const long *lp)
161{
162        int32_t l;
163
164        if ((xdrs->x_handy -= sizeof(int32_t)) < 0)
165                return (FALSE);
166        l = htonl(*lp);
167        memcpy(xdrs->x_private, &l, sizeof(int32_t));
168        xdrs->x_private += sizeof(int32_t);
169        return (TRUE);
170}
171
172static bool_t
173xdrmem_getbytes(
174        XDR *xdrs,
175        caddr_t addr,
176        u_int len)
177{
178
179        if ((xdrs->x_handy -= len) < 0)
180                return (FALSE);
181        memcpy(addr, xdrs->x_private, len);
182        xdrs->x_private += len;
183        return (TRUE);
184}
185
186static bool_t
187xdrmem_putbytes(
188        XDR *xdrs,
189        const char *addr,
190        u_int len)
191{
192
193        if ((xdrs->x_handy -= len) < 0)
194                return (FALSE);
195        memcpy(xdrs->x_private, addr, len);
196        xdrs->x_private += len;
197        return (TRUE);
198}
199
200static u_int
201xdrmem_getpos(
202        XDR *xdrs)
203{
204
205        /* XXX w/64-bit pointers, u_int not enough! */
206        return ((uintptr_t)xdrs->x_private - (uintptr_t)xdrs->x_base);
207}
208
209static bool_t
210xdrmem_setpos(
211        XDR *xdrs,
212        u_int pos)
213{
214        void *newaddr = xdrs->x_base + pos;
215        void *lastaddr = xdrs->x_private + xdrs->x_handy;
216
217        if (newaddr > lastaddr)
218                return (FALSE);
219        xdrs->x_private = newaddr;
220        xdrs->x_handy = (intptr_t)lastaddr - (intptr_t)newaddr;
221        return (TRUE);
222}
223
224static int32_t *
225xdrmem_inline_aligned(
226        XDR *xdrs,
227        u_int len)
228{
229        int32_t *buf = 0;
230
231        if (xdrs->x_handy >= len) {
232                xdrs->x_handy -= len;
233                buf = (int32_t *)xdrs->x_private;
234                xdrs->x_private += len;
235        }
236        return (buf);
237}
238
239static int32_t *
240xdrmem_inline_unaligned(
241        XDR *xdrs,
242        u_int len)
243{
244       
245        return (0);
246}
Note: See TracBrowser for help on using the repository browser.