3 * Copyright (c) 2009, Sun Microsystems, Inc.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are met:
8 * - Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
10 * - Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 * - Neither the name of Sun Microsystems, Inc. nor the names of its
14 * contributors may be used to endorse or promote products derived
15 * from this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27 * POSSIBILITY OF SUCH DAMAGE.
31 * xdr_array.c, Generic XDR routines impelmentation.
33 * Copyright (C) 1984, Sun Microsystems, Inc.
35 * These are the "non-trivial" xdr primitives used to serialize and de-serialize
36 * arrays. See xdr.h for more info on the interface to xdr.
44 #include <rpc/types.h>
47 #include "xdr_private.h"
50 * XDR an array of arbitrary elements
51 * *addrp is a pointer to the array, *sizep is the number of elements.
52 * If addrp is NULL (*sizep * elsize) bytes are allocated.
53 * elsize is the size (in bytes) of each element, and elproc is the
54 * xdr procedure to call to handle each element of the array.
57 xdr_array (XDR
* xdrs
,
65 caddr_t target
= *addrp
;
66 u_int c
; /* the actual element count */
70 /* like strings, arrays are really counted arrays */
71 if (!xdr_u_int (xdrs
, sizep
))
76 if ((c
> maxsize
|| UINT_MAX
/ elsize
< c
) && (xdrs
->x_op
!= XDR_FREE
))
80 nodesize
= c
* elsize
;
83 * if we are deserializing, we may need to allocate an array.
84 * We also save time by checking for a null array if we are freeing.
92 *addrp
= target
= mem_alloc (nodesize
);
95 xdr_warnx ("xdr_array: out of memory");
99 memset (target
, 0, nodesize
);
110 * now we xdr each element of array
112 for (i
= 0; (i
< c
) && stat
; i
++)
114 stat
= (*elproc
) (xdrs
, target
);
119 * the array may need freeing
121 if (xdrs
->x_op
== XDR_FREE
)
123 mem_free (*addrp
, nodesize
);
132 * XDR a fixed length array. Unlike variable-length arrays,
133 * the storage of fixed length arrays is static and unfreeable.
134 * > basep: base of the array
135 * > size: size of the array
136 * > elemsize: size of each element
137 * > xdr_elem: routine to XDR each element
140 xdr_vector (XDR
* xdrs
,
150 for (i
= 0; i
< nelem
; i
++)
152 if (!(*xdr_elem
) (xdrs
, elptr
))