The R Project SVN R

Rev

Rev 38709 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 38709 Rev 56474
Line 52... Line 52...
52
 * xdr.
52
 * xdr.
53
 */
53
 */
54
 
54
 
55
#include <stdlib.h>
55
#include <stdlib.h>
56
#include <stdio.h>
56
#include <stdio.h>
57
/*char *malloc();*/
-
 
58
#include <string.h> /* strlen */
57
#include <string.h> /* strlen */
59
 
-
 
-
 
58
#include <stdint.h>
60
 
59
 
61
#include <rpc/types.h>
60
#include <rpc/types.h>
62
#include <rpc/xdr.h>
61
#include <rpc/xdr.h>
63
 
62
 
64
/* R-specific */
63
/* R-specific */
65
void REprintf(char*, ...);
64
void REprintf(char*, ...);
66
#define fprintf(a, b) REprintf(b)
65
#define fprintf(a, b) REprintf(b)
67
 
66
 
68
 
67
#ifdef UNUSED
69
/*
68
/*
70
 * constants specific to the xdr "protocol"
69
 * constants specific to the xdr "protocol"
71
 */
70
 */
72
#define XDR_FALSE	((long) 0)
71
#define XDR_FALSE	((int32_t) 0)
73
#define XDR_TRUE	((long) 1)
72
#define XDR_TRUE	((int32_t) 1)
74
#define LASTUNSIGNED	((u_int) 0-1)
73
#define LASTUNSIGNED	((u_int) 0-1)
-
 
74
#endif
75
 
75
 
76
/*
76
/*
77
 * for unit alignment
77
 * for unit alignment
78
 */
78
 */
79
static char xdr_zero[BYTES_PER_XDR_UNIT] = { 0, 0, 0, 0 };
79
static char xdr_zero[BYTES_PER_XDR_UNIT] = { 0, 0, 0, 0 };
80
 
80
 
-
 
81
#ifdef UNUSED
81
/*
82
/*
82
 * Free a data structure using XDR
83
 * Free a data structure using XDR
83
 * Not a filter, but a convenient utility nonetheless
84
 * Not a filter, but a convenient utility nonetheless
84
 */
85
 */
85
void
86
void
Line 90... Line 91...
90
	XDR x;
91
	XDR x;
91
 
92
 
92
	x.x_op = XDR_FREE;
93
	x.x_op = XDR_FREE;
93
	(*proc)(&x, objp);
94
	(*proc)(&x, objp);
94
}
95
}
-
 
96
#endif
95
 
97
 
-
 
98
#ifdef UNUSED
96
/*
99
/*
97
 * XDR nothing
100
 * XDR nothing
98
 */
101
 */
99
bool_t
102
bool_t
100
xdr_void(/* xdrs, addr */)
103
xdr_void(/* xdrs, addr */)
Line 102... Line 105...
102
	/* caddr_t addr; */
105
	/* caddr_t addr; */
103
{
106
{
104
 
107
 
105
	return (TRUE);
108
	return (TRUE);
106
}
109
}
-
 
110
#endif
107
 
111
 
108
/*
112
/*
109
 * XDR integers
113
 * XDR integers: always 32-bit in R
110
 */
114
 */
111
bool_t
115
bool_t
112
xdr_int(xdrs, ip)
116
xdr_int(xdrs, ip)
113
	XDR *xdrs;
117
	XDR *xdrs;
114
	int *ip;
118
	int *ip;
115
{
119
{
-
 
120
//    return (xdr_long(xdrs, (int32_t *)ip));
116
 
121
 
117
#ifdef lint
-
 
118
	(void) (xdr_short(xdrs, (short *)ip));
122
	if (xdrs->x_op == XDR_DECODE)
119
	return (xdr_long(xdrs, (long *)ip));
123
		return (XDR_GETLONG(xdrs, (int32_t *)ip));
120
#else
-
 
121
	if (sizeof (int) == sizeof (long)) {
124
	if (xdrs->x_op == XDR_ENCODE)
122
		return (xdr_long(xdrs, (long *)ip));
125
		return (XDR_PUTLONG(xdrs, (int32_t *)ip));
123
	} else {
126
	if (xdrs->x_op == XDR_FREE)
124
		return (xdr_short(xdrs, (short *)ip));
127
		return (TRUE);
125
	}
-
 
126
#endif
128
	return (FALSE);
127
}
129
}
128
 
130
 
129
/*
131
/*
130
 * XDR unsigned integers
132
 * XDR unsigned integers: always 32-bit in R
131
 */
133
 */
132
bool_t
134
bool_t
133
xdr_u_int(xdrs, up)
135
xdr_u_int(xdrs, up)
134
	XDR *xdrs;
136
	XDR *xdrs;
135
	u_int *up;
137
	u_int *up;
136
{
138
{
-
 
139
//    return (xdr_u_long(xdrs, (uint32_t *)up));
-
 
140
 
-
 
141
	if (xdrs->x_op == XDR_DECODE)
-
 
142
		return (XDR_GETLONG(xdrs, (int32_t *)up));
-
 
143
	if (xdrs->x_op == XDR_ENCODE)
-
 
144
		return (XDR_PUTLONG(xdrs, (int32_t *)up));
-
 
145
	if (xdrs->x_op == XDR_FREE)
-
 
146
		return (TRUE);
-
 
147
	return (FALSE);
137
 
148
 
138
#ifdef lint
-
 
139
	(void) (xdr_short(xdrs, (short *)up));
-
 
140
	return (xdr_u_long(xdrs, (u_long *)up));
-
 
141
#else
-
 
142
	if (sizeof (u_int) == sizeof (u_long)) {
-
 
143
		return (xdr_u_long(xdrs, (u_long *)up));
-
 
144
	} else {
-
 
145
		return (xdr_short(xdrs, (short *)up));
-
 
146
	}
-
 
147
#endif
-
 
148
}
149
}
149
 
150
 
-
 
151
#ifdef UNUSED
150
/*
152
/*
151
 * XDR long integers
153
 * XDR long integers
152
 * same as xdr_u_long - open coded to save a proc call!
154
 * same as xdr_u_long - open coded to save a proc call!
153
 */
155
 */
154
bool_t
156
bool_t
155
xdr_long(xdrs, lp)
157
xdr_long(xdrs, lp)
156
	register XDR *xdrs;
158
	register XDR *xdrs;
157
	long *lp;
159
	int32_t *lp;
158
{
160
{
159
 
161
 
160
	if (xdrs->x_op == XDR_ENCODE)
162
	if (xdrs->x_op == XDR_ENCODE)
161
		return (XDR_PUTLONG(xdrs, lp));
163
		return (XDR_PUTLONG(xdrs, lp));
162
 
164
 
Line 174... Line 176...
174
 * same as xdr_long - open coded to save a proc call!
176
 * same as xdr_long - open coded to save a proc call!
175
 */
177
 */
176
bool_t
178
bool_t
177
xdr_u_long(xdrs, ulp)
179
xdr_u_long(xdrs, ulp)
178
	register XDR *xdrs;
180
	register XDR *xdrs;
179
	u_long *ulp;
181
	uint32_t *ulp;
180
{
182
{
181
 
183
 
182
	if (xdrs->x_op == XDR_DECODE)
184
	if (xdrs->x_op == XDR_DECODE)
183
		return (XDR_GETLONG(xdrs, (long *)ulp));
185
		return (XDR_GETLONG(xdrs, (int32_t *)ulp));
184
	if (xdrs->x_op == XDR_ENCODE)
186
	if (xdrs->x_op == XDR_ENCODE)
185
		return (XDR_PUTLONG(xdrs, (long *)ulp));
187
		return (XDR_PUTLONG(xdrs, (int32_t *)ulp));
186
	if (xdrs->x_op == XDR_FREE)
188
	if (xdrs->x_op == XDR_FREE)
187
		return (TRUE);
189
		return (TRUE);
188
	return (FALSE);
190
	return (FALSE);
189
}
191
}
190
 
192
 
Line 194... Line 196...
194
bool_t
196
bool_t
195
xdr_short(xdrs, sp)
197
xdr_short(xdrs, sp)
196
	register XDR *xdrs;
198
	register XDR *xdrs;
197
	short *sp;
199
	short *sp;
198
{
200
{
199
	long l;
201
	int32_t l;
200
 
202
 
201
	switch (xdrs->x_op) {
203
	switch (xdrs->x_op) {
202
 
204
 
203
	case XDR_ENCODE:
205
	case XDR_ENCODE:
204
		l = (long) *sp;
206
		l = (int32_t) *sp;
205
		return (XDR_PUTLONG(xdrs, &l));
207
		return (XDR_PUTLONG(xdrs, &l));
206
 
208
 
207
	case XDR_DECODE:
209
	case XDR_DECODE:
208
		if (!XDR_GETLONG(xdrs, &l)) {
210
		if (!XDR_GETLONG(xdrs, &l)) {
209
			return (FALSE);
211
			return (FALSE);
Line 223... Line 225...
223
bool_t
225
bool_t
224
xdr_u_short(xdrs, usp)
226
xdr_u_short(xdrs, usp)
225
	register XDR *xdrs;
227
	register XDR *xdrs;
226
	u_short *usp;
228
	u_short *usp;
227
{
229
{
228
	u_long l;
230
	uint32_t l;
229
 
231
 
230
	switch (xdrs->x_op) {
232
	switch (xdrs->x_op) {
231
 
233
 
232
	case XDR_ENCODE:
234
	case XDR_ENCODE:
233
		l = (u_long) *usp;
235
		l = (uint32_t) *usp;
234
		return (XDR_PUTLONG(xdrs, &l));
236
		return (XDR_PUTLONG(xdrs, &l));
235
 
237
 
236
	case XDR_DECODE:
238
	case XDR_DECODE:
237
		if (!XDR_GETLONG(xdrs, &l)) {
239
		if (!XDR_GETLONG(xdrs, &l)) {
238
			return (FALSE);
240
			return (FALSE);
Line 244... Line 246...
244
		return (TRUE);
246
		return (TRUE);
245
	}
247
	}
246
	return (FALSE);
248
	return (FALSE);
247
}
249
}
248
 
250
 
249
 
-
 
250
/*
251
/*
251
 * XDR a char
252
 * XDR a char
252
 */
253
 */
253
bool_t
254
bool_t
254
xdr_char(xdrs, cp)
255
xdr_char(xdrs, cp)
Line 289... Line 290...
289
bool_t
290
bool_t
290
xdr_bool(xdrs, bp)
291
xdr_bool(xdrs, bp)
291
	register XDR *xdrs;
292
	register XDR *xdrs;
292
	bool_t *bp;
293
	bool_t *bp;
293
{
294
{
294
	long lb;
295
	int32_t lb;
295
 
296
 
296
	switch (xdrs->x_op) {
297
	switch (xdrs->x_op) {
297
 
298
 
298
	case XDR_ENCODE:
299
	case XDR_ENCODE:
299
		lb = *bp ? XDR_TRUE : XDR_FALSE;
300
		lb = *bp ? XDR_TRUE : XDR_FALSE;
Line 324... Line 325...
324
	enum sizecheck { SIZEVAL };	/* used to find the size of an enum */
325
	enum sizecheck { SIZEVAL };	/* used to find the size of an enum */
325
 
326
 
326
	/*
327
	/*
327
	 * enums are treated as ints
328
	 * enums are treated as ints
328
	 */
329
	 */
329
	if (sizeof (enum sizecheck) == sizeof (long)) {
330
	if (sizeof (enum sizecheck) == sizeof (int32_t)) {
330
		return (xdr_long(xdrs, (long *)ep));
331
		return (xdr_long(xdrs, (int32_t *)ep));
331
	} else if (sizeof (enum sizecheck) == sizeof (short)) {
332
	} else if (sizeof (enum sizecheck) == sizeof (short)) {
332
		return (xdr_short(xdrs, (short *)ep));
333
		return (xdr_short(xdrs, (short *)ep));
333
	} else {
334
	} else {
334
		return (FALSE);
335
		return (FALSE);
335
	}
336
	}
336
#else
337
#else
337
	(void) (xdr_short(xdrs, (short *)ep));
338
	(void) (xdr_short(xdrs, (short *)ep));
338
	return (xdr_long(xdrs, (long *)ep));
339
	return (xdr_long(xdrs, (int32_t *)ep));
339
#endif
340
#endif
340
}
341
}
-
 
342
#endif
341
 
343
 
342
/*
344
/*
343
 * XDR opaque data
345
 * XDR opaque data
344
 * Allows the specification of a fixed size sequence of opaque bytes.
346
 * Allows the specification of a fixed size sequence of opaque bytes.
345
 * cp points to the opaque object and cnt gives the byte length.
347
 * cp points to the opaque object and cnt gives the byte length.
Line 446... Line 448...
446
		return (TRUE);
448
		return (TRUE);
447
	}
449
	}
448
	return (FALSE);
450
	return (FALSE);
449
}
451
}
450
 
452
 
-
 
453
#ifdef UNUSED
451
/*
454
/*
452
 * Implemented here due to commonality of the object.
455
 * Implemented here due to commonality of the object.
453
 */
456
 */
454
bool_t
457
bool_t
455
xdr_netobj(xdrs, np)
458
xdr_netobj(xdrs, np)
Line 502... Line 505...
502
	 * no match - execute the default xdr routine if there is one
505
	 * no match - execute the default xdr routine if there is one
503
	 */
506
	 */
504
	return ((dfault == NULL_xdrproc_t) ? FALSE :
507
	return ((dfault == NULL_xdrproc_t) ? FALSE :
505
	    (*dfault)(xdrs, unp, LASTUNSIGNED));
508
	    (*dfault)(xdrs, unp, LASTUNSIGNED));
506
}
509
}
507
 
510
#endif
508
 
511
 
509
/*
512
/*
510
 * Non-portable xdr primitives.
513
 * Non-portable xdr primitives.
511
 * Care should be taken when moving these routines to new architectures.
514
 * Care should be taken when moving these routines to new architectures.
512
 */
515
 */
Line 581... Line 584...
581
		return (TRUE);
584
		return (TRUE);
582
	}
585
	}
583
	return (FALSE);
586
	return (FALSE);
584
}
587
}
585
 
588
 
-
 
589
#ifdef UNUSED
586
/*
590
/*
587
 * Wrapper for xdr_string that can be called directly from
591
 * Wrapper for xdr_string that can be called directly from
588
 * routines like clnt_call
592
 * routines like clnt_call
589
 */
593
 */
590
bool_t
594
bool_t
Line 595... Line 599...
595
	if (xdr_string(xdrs, cpp, LASTUNSIGNED)) {
599
	if (xdr_string(xdrs, cpp, LASTUNSIGNED)) {
596
		return (TRUE);
600
		return (TRUE);
597
	}
601
	}
598
	return (FALSE);
602
	return (FALSE);
599
}
603
}
-
 
604
#endif