2 static char sfs_xdr_array_id[] = "@(#)xdr_array.c 2.1 97/10/23";
4 /* @(#)xdr_array.c 2.1 88/07/29 4.0 RPCSRC */
6 * Copyright (c) 1992-1997,2001 by Standard Performance Evaluation Corporation
8 * Standard Performance Evaluation Corporation (SPEC)
9 * 6585 Merchant Place, Suite 100
12 * This product contains benchmarks acquired from several sources who
13 * understand and agree with SPEC's goal of creating fair and objective
14 * benchmarks to measure computer performance.
16 * This copyright notice is placed here only to protect SPEC in the
17 * event the source is misused in any manner that is contrary to the
18 * spirit, the goals and the intent of SPEC.
20 * The source code is provided to the user or company under the license
21 * agreement for the SPEC Benchmark Suite for this product.
24 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
25 * unrestricted use provided that this legend is included on all tape
26 * media and as a part of the software program in whole or part. Users
27 * may copy or modify Sun RPC without charge, but are not authorized
28 * to license or distribute it to anyone else except as part of a product or
29 * program developed by the user.
31 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
32 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
33 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
35 * Sun RPC is provided with no support and without any obligation on the
36 * part of Sun Microsystems, Inc. to assist in its use, correction,
37 * modification or enhancement.
39 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
40 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
41 * OR ANY PART THEREOF.
43 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
44 * or profits or other special, indirect and consequential damages, even if
45 * Sun has been advised of the possibility of such damages.
47 * Sun Microsystems, Inc.
49 * Mountain View, California 94043
51 #if !defined(lint) && defined(SCCSIDS)
52 static char sccsid[] = "@(#)xdr_array.c 1.10 87/08/11 Copyr 1984 Sun Micro";
56 * xdr_array.c, Generic XDR routines impelmentation.
58 * Copyright (C) 1984, Sun Microsystems, Inc.
60 * These are the "non-trivial" xdr primitives used to serialize and de-serialize
61 * arrays. See xdr.h for more info on the interface to xdr.
67 #include "rpc/types.h"
70 #define LASTUNSIGNED ((uint_t)0-1)
74 * XDR an array of arbitrary elements
75 * *addrp is a pointer to the array, *sizep is the number of elements.
76 * If addrp is NULL (*sizep * elsize) bytes are allocated.
77 * elsize is the size (in bytes) of each element, and elproc is the
78 * xdr procedure to call to handle each element of the array.
83 void **addrp, /* array pointer */
84 uint_t *sizep, /* number of elements */
85 uint_t maxsize, /* max numberof elements */
86 uint_t elsize, /* size in bytes of each element */
87 xdrproc_t elproc) /* xdr routine to handle each element */
90 char * target = *addrp;
91 uint_t c; /* the actual element count */
95 /* like strings, arrays are really counted arrays */
96 if (! xdr_u_int(xdrs, sizep)) {
100 if ((c > maxsize) && (xdrs->x_op != XDR_FREE)) {
103 nodesize = c * elsize;
106 * if we are deserializing, we may need to allocate an array.
107 * We also save time by checking for a null array if we are freeing.
110 switch (xdrs->x_op) {
114 *addrp = target = mem_alloc(nodesize);
115 if (target == NULL) {
116 (void) fprintf(stderr,
117 "xdr_array: out of memory\n");
120 memset(target, '\0', nodesize);
128 * now we xdr each element of array
130 for (i = 0; (i < c) && stat; i++) {
131 stat = (*elproc)(xdrs, target, LASTUNSIGNED);
136 * the array may need freeing
138 if (xdrs->x_op == XDR_FREE) {
139 mem_free(*addrp, nodesize);
148 * XDR a fixed length array. Unlike variable-length arrays,
149 * the storage of fixed length arrays is static and unfreeable.
150 * > basep: base of the array
151 * > size: size of the array
152 * > elemsize: size of each element
153 * > xdr_elem: routine to XDR each element
167 for (i = 0; i < nelem; i++) {
168 if (! (*xdr_elem)(xdrs, elptr, LASTUNSIGNED)) {