Import Upstream version 1.8.5
[hcoop/debian/openafs.git] / src / rx / xdr_update.c
1 /*
2 * xdr_update.c: Additions to release 3.0 XDR routines required
3 * for rpcgen. These routines are from release 3.2BETA and
4 * may be updated before final release.
5 *
6 * Copyright (C) 1986, Sun Microsystems, Inc.
7 *
8 */
9 #include <afsconfig.h>
10 #include <afs/param.h>
11
12
13 #ifndef NeXT
14 #include "xdr.h"
15
16 #ifdef NULL /* Strict ANSI-C aborts if we redefine this */
17 #undef NULL
18 #endif
19
20 #define NULL 0
21
22 #define LASTUNSIGNED ((u_int)0-1)
23
24 /*
25 * xdr_pointer():
26 *
27 * XDR a pointer to a possibly recursive data structure. This
28 * differs with xdr_reference in that it can serialize/deserialiaze
29 * trees correctly.
30 *
31 * What's sent is actually a union:
32 *
33 * union object_pointer switch (boolean b) {
34 * case TRUE: object_data data;
35 * case FALSE: void nothing;
36 * }
37 *
38 * > objpp: Pointer to the pointer to the object.
39 * > obj_size: size of the object.
40 * > xdr_obj: routine to XDR an object.
41 *
42 */
43 bool_t
44 xdr_pointer(XDR * xdrs, char **objpp, u_int obj_size,
45 xdrproc_t xdr_obj)
46 {
47
48 bool_t more_data;
49
50 more_data = (*objpp != NULL);
51 if (!xdr_bool(xdrs, &more_data)) {
52 return (FALSE);
53 }
54 if (!more_data) {
55 *objpp = NULL;
56 return (TRUE);
57 }
58 return (xdr_reference(xdrs, objpp, obj_size, xdr_obj));
59 }
60
61 /*
62 * xdr_vector():
63 *
64 * XDR a fixed length array. Unlike variable-length arrays,
65 * the storage of fixed length arrays is static and unfreeable.
66 * > basep: base of the array
67 * > size: size of the array
68 * > elemsize: size of each element
69 * > xdr_elem: routine to XDR each element
70 */
71 bool_t
72 xdr_vector(XDR * xdrs, char *basep, u_int nelem,
73 u_int elemsize, xdrproc_t xdr_elem)
74 {
75 u_int i;
76 char *elptr;
77
78 elptr = basep;
79 for (i = 0; i < nelem; i++) {
80 if (!(*xdr_elem) (xdrs, elptr, LASTUNSIGNED)) {
81 return (FALSE);
82 }
83 elptr += elemsize;
84 }
85 return (TRUE);
86 }
87 #endif /* NeXT */