4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
31 * Portions of this source code were derived from Berkeley 4.3 BSD
32 * under license from the Regents of the University of California.
35 #pragma ident "%Z%%M% %I% %E% SMI"
38 * xdr_array.c, Generic XDR routines impelmentation.
39 * These are the "non-trivial" xdr primitives used to serialize and de-serialize
40 * arrays. See xdr.h for more info on the interface to xdr.
43 #include <sys/param.h>
44 #include <sys/cmn_err.h>
45 #include <sys/types.h>
46 #include <sys/systm.h>
48 #include <rpc/types.h>
51 #define LASTUNSIGNED ((uint_t)0-1)
54 * XDR an array of arbitrary elements
55 * *addrp is a pointer to the array, *sizep is the number of elements.
56 * If addrp is NULL (*sizep * elsize) bytes are allocated.
57 * elsize is the size (in bytes) of each element, and elproc is the
58 * xdr procedure to call to handle each element of the array.
61 xdr_array(XDR *xdrs, caddr_t *addrp, uint_t *sizep, const uint_t maxsize,
62 const uint_t elsize, const xdrproc_t elproc)
65 caddr_t target = *addrp;
66 uint_t c; /* the actual element count */
70 /* like strings, arrays are really counted arrays */
71 if (!xdr_u_int(xdrs, sizep)) {
73 printf("xdr_array: size FAILED\n");
78 if ((c > maxsize || LASTUNSIGNED / elsize < c) &&
79 xdrs->x_op != XDR_FREE) {
81 printf("xdr_array: bad size FAILED\n");
85 nodesize = c * elsize;
88 * if we are deserializing, we may need to allocate an array.
89 * We also save time by checking for a null array if we are freeing.
96 *addrp = target = (char *)mem_alloc(nodesize);
97 bzero(target, nodesize);
108 * now we xdr each element of array
110 for (i = 0; (i < c) && stat; i++) {
111 stat = (*elproc)(xdrs, target, LASTUNSIGNED);
116 * the array may need freeing
118 if (xdrs->x_op == XDR_FREE) {
119 mem_free(*addrp, nodesize);