4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
27 /* All Rights Reserved */
30 * Portions of this source code were derived from Berkeley 4.3 BSD
31 * under license from the Regents of the University of California.
35 * xdr_array.c, Generic XDR routines impelmentation.
36 * These are the "non-trivial" xdr primitives used to serialize and de-serialize
37 * arrays. See xdr.h for more info on the interface to xdr.
40 #include <sys/param.h>
41 #include <sys/cmn_err.h>
42 #include <sys/types.h>
43 #include <sys/systm.h>
45 #include <rpc/types.h>
48 #define LASTUNSIGNED ((uint_t)0-1)
51 * XDR an array of arbitrary elements
52 * *addrp is a pointer to the array, *sizep is the number of elements.
53 * If addrp is NULL (*sizep * elsize) bytes are allocated.
54 * elsize is the size (in bytes) of each element, and elproc is the
55 * xdr procedure to call to handle each element of the array.
58 xdr_array(XDR
*xdrs
, caddr_t
*addrp
, uint_t
*sizep
, const uint_t maxsize
,
59 const uint_t elsize
, const xdrproc_t elproc
)
62 caddr_t target
= *addrp
;
63 uint_t c
; /* the actual element count */
67 /* like strings, arrays are really counted arrays */
68 if (!xdr_u_int(xdrs
, sizep
)) {
72 if ((c
> maxsize
|| LASTUNSIGNED
/ elsize
< c
) &&
73 xdrs
->x_op
!= XDR_FREE
) {
76 nodesize
= c
* elsize
;
79 * if we are deserializing, we may need to allocate an array.
80 * We also save time by checking for a null array if we are freeing.
87 *addrp
= target
= (char *)mem_alloc(nodesize
);
88 bzero(target
, nodesize
);
99 * now we xdr each element of array
101 for (i
= 0; (i
< c
) && stat
; i
++) {
102 stat
= (*elproc
)(xdrs
, target
, LASTUNSIGNED
);
107 * the array may need freeing
109 if (xdrs
->x_op
== XDR_FREE
) {
110 mem_free(*addrp
, nodesize
);