2 * Copyright (c) 2010, Oracle America, Inc.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following
12 * disclaimer in the documentation and/or other materials
13 * provided with the distribution.
14 * * Neither the name of the "Oracle America, Inc." nor the names of its
15 * contributors may be used to endorse or promote products derived
16 * from this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
23 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
25 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
27 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
28 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 * General purpose routine to see how much space something will use
35 * when serialized using XDR.
38 #include <sys/cdefs.h>
39 __FBSDID("$FreeBSD$");
41 #include "namespace.h"
42 #include <rpc/types.h>
44 #include <sys/types.h>
46 #include "un-namespace.h"
50 x_putlong(xdrs, longp)
54 xdrs->x_handy += BYTES_PER_XDR_UNIT;
60 x_putbytes(xdrs, bp, len)
73 return (xdrs->x_handy);
82 /* This is not allowed */
94 if (xdrs->x_op != XDR_ENCODE) {
97 if (len < (u_int)(uintptr_t)xdrs->x_base) {
98 /* x_private was already allocated */
100 return ((int32_t *) xdrs->x_private);
102 /* Free the earlier space and allocate new area */
104 free(xdrs->x_private);
105 if ((xdrs->x_private = (caddr_t) malloc(len)) == NULL) {
109 xdrs->x_base = (caddr_t)(uintptr_t)len;
110 xdrs->x_handy += len;
111 return ((int32_t *) xdrs->x_private);
118 /* Always return FALSE/NULL, as the case may be */
128 if (xdrs->x_private) {
129 free(xdrs->x_private);
130 xdrs->x_private = NULL;
136 xdr_sizeof(func, data)
143 /* to stop ANSI-C compiler from complaining */
144 typedef bool_t (* dummyfunc1)(XDR *, long *);
145 typedef bool_t (* dummyfunc2)(XDR *, caddr_t, u_int);
147 ops.x_putlong = x_putlong;
148 ops.x_putbytes = x_putbytes;
149 ops.x_inline = x_inline;
150 ops.x_getpostn = x_getpostn;
151 ops.x_setpostn = x_setpostn;
152 ops.x_destroy = x_destroy;
154 /* the other harmless ones */
155 ops.x_getlong = (dummyfunc1) harmless;
156 ops.x_getbytes = (dummyfunc2) harmless;
161 x.x_private = (caddr_t) NULL;
162 x.x_base = (caddr_t) 0;
164 stat = func(&x, data);
167 return (stat == TRUE ? (unsigned) x.x_handy: 0);