OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [rtems-20020807/] [cpukit/] [librpc/] [src/] [xdr/] [xdr_mem.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1026 ivang
/*
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";*/
33
static 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
#include <string.h>
48
#include <rpc/types.h>
49
#include <rpc/xdr.h>
50
#include <netinet/in.h>
51
 
52
static bool_t   xdrmem_getlong_aligned();
53
static bool_t   xdrmem_putlong_aligned();
54
static bool_t   xdrmem_getlong_unaligned();
55
static bool_t   xdrmem_putlong_unaligned();
56
static bool_t   xdrmem_getbytes();
57
static bool_t   xdrmem_putbytes();
58
static u_int    xdrmem_getpos(); /* XXX w/64-bit pointers, u_int not enough! */
59
static bool_t   xdrmem_setpos();
60
static int32_t *xdrmem_inline_aligned();
61
static int32_t *xdrmem_inline_unaligned();
62
static void     xdrmem_destroy();
63
 
64
static struct   xdr_ops xdrmem_ops_aligned = {
65
        xdrmem_getlong_aligned,
66
        xdrmem_putlong_aligned,
67
        xdrmem_getbytes,
68
        xdrmem_putbytes,
69
        xdrmem_getpos,
70
        xdrmem_setpos,
71
        xdrmem_inline_aligned,
72
        xdrmem_destroy
73
};
74
 
75
static struct   xdr_ops xdrmem_ops_unaligned = {
76
        xdrmem_getlong_unaligned,
77
        xdrmem_putlong_unaligned,
78
        xdrmem_getbytes,
79
        xdrmem_putbytes,
80
        xdrmem_getpos,
81
        xdrmem_setpos,
82
        xdrmem_inline_unaligned,
83
        xdrmem_destroy
84
};
85
 
86
/*
87
 * The procedure xdrmem_create initializes a stream descriptor for a
88
 * memory buffer.
89
 */
90
void
91
xdrmem_create(xdrs, addr, size, op)
92
        register XDR *xdrs;
93
        caddr_t addr;
94
        u_int size;
95
        enum xdr_op op;
96
{
97
 
98
        xdrs->x_op = op;
99
        xdrs->x_ops = ((size_t)addr & (sizeof(int32_t) - 1))
100
                ? &xdrmem_ops_unaligned : &xdrmem_ops_aligned;
101
        xdrs->x_private = xdrs->x_base = addr;
102
        xdrs->x_handy = size;
103
}
104
 
105
static void
106
xdrmem_destroy(/*xdrs*/)
107
        /*XDR *xdrs;*/
108
{
109
 
110
}
111
 
112
static bool_t
113
xdrmem_getlong_aligned(xdrs, lp)
114
        register XDR *xdrs;
115
        long *lp;
116
{
117
 
118
        if ((xdrs->x_handy -= sizeof(int32_t)) < 0)
119
                return (FALSE);
120
        *lp = ntohl(*(int32_t *)(xdrs->x_private));
121
        xdrs->x_private += sizeof(int32_t);
122
        return (TRUE);
123
}
124
 
125
static bool_t
126
xdrmem_putlong_aligned(xdrs, lp)
127
        register XDR *xdrs;
128
        long *lp;
129
{
130
 
131
        if ((xdrs->x_handy -= sizeof(int32_t)) < 0)
132
                return (FALSE);
133
        *(int32_t *)xdrs->x_private = htonl(*lp);
134
        xdrs->x_private += sizeof(int32_t);
135
        return (TRUE);
136
}
137
 
138
static bool_t
139
xdrmem_getlong_unaligned(xdrs, lp)
140
        register XDR *xdrs;
141
        long *lp;
142
{
143
        int32_t l;
144
 
145
        if ((xdrs->x_handy -= sizeof(int32_t)) < 0)
146
                return (FALSE);
147
        memcpy(&l, xdrs->x_private, sizeof(int32_t));
148
        *lp = ntohl(l);
149
        xdrs->x_private += sizeof(int32_t);
150
        return (TRUE);
151
}
152
 
153
static bool_t
154
xdrmem_putlong_unaligned(xdrs, lp)
155
        register XDR *xdrs;
156
        long *lp;
157
{
158
        int32_t l;
159
 
160
        if ((xdrs->x_handy -= sizeof(int32_t)) < 0)
161
                return (FALSE);
162
        l = htonl(*lp);
163
        memcpy(xdrs->x_private, &l, sizeof(int32_t));
164
        xdrs->x_private += sizeof(int32_t);
165
        return (TRUE);
166
}
167
 
168
static bool_t
169
xdrmem_getbytes(xdrs, addr, len)
170
        register XDR *xdrs;
171
        caddr_t addr;
172
        register u_int len;
173
{
174
 
175
        if ((xdrs->x_handy -= len) < 0)
176
                return (FALSE);
177
        memcpy(addr, xdrs->x_private, len);
178
        xdrs->x_private += len;
179
        return (TRUE);
180
}
181
 
182
static bool_t
183
xdrmem_putbytes(xdrs, addr, len)
184
        register XDR *xdrs;
185
        caddr_t addr;
186
        register u_int len;
187
{
188
 
189
        if ((xdrs->x_handy -= len) < 0)
190
                return (FALSE);
191
        memcpy(xdrs->x_private, addr, len);
192
        xdrs->x_private += len;
193
        return (TRUE);
194
}
195
 
196
static u_int
197
xdrmem_getpos(xdrs)
198
        register XDR *xdrs;
199
{
200
 
201
        /* XXX w/64-bit pointers, u_int not enough! */
202
        return ((u_long)xdrs->x_private - (u_long)xdrs->x_base);
203
}
204
 
205
static bool_t
206
xdrmem_setpos(xdrs, pos)
207
        register XDR *xdrs;
208
        u_int pos;
209
{
210
        register caddr_t newaddr = xdrs->x_base + pos;
211
        register caddr_t lastaddr = xdrs->x_private + xdrs->x_handy;
212
 
213
        if ((long)newaddr > (long)lastaddr)
214
                return (FALSE);
215
        xdrs->x_private = newaddr;
216
        xdrs->x_handy = (long)lastaddr - (long)newaddr;
217
        return (TRUE);
218
}
219
 
220
static int32_t *
221
xdrmem_inline_aligned(xdrs, len)
222
        register XDR *xdrs;
223
        int len;
224
{
225
        int32_t *buf = 0;
226
 
227
        if (xdrs->x_handy >= len) {
228
                xdrs->x_handy -= len;
229
                buf = (int32_t *) xdrs->x_private;
230
                xdrs->x_private += len;
231
        }
232
        return (buf);
233
}
234
 
235
static int32_t *
236
xdrmem_inline_unaligned(xdrs, len)
237
        register XDR *xdrs;
238
        int len;
239
{
240
 
241
        return (0);
242
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.