2 * Copyright (c) 2006,2011-2014 Apple Inc. All Rights Reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
25 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
26 * unrestricted use provided that this legend is included on all tape
27 * media and as a part of the software program in whole or part. Users
28 * may copy or modify Sun RPC without charge, but are not authorized
29 * to license or distribute it to anyone else except as part of a product or
30 * program developed by the user.
32 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
33 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
34 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
36 * Sun RPC is provided with no support and without any obligation on the
37 * part of Sun Microsystems, Inc. to assist in its use, correction,
38 * modification or enhancement.
40 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
41 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
42 * OR ANY PART THEREOF.
44 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
45 * or profits or other special, indirect and consequential damages, even if
46 * Sun has been advised of the possibility of such damages.
48 * Sun Microsystems, Inc.
50 * Mountain View, California 94043
55 * Copyright 1990 Sun Microsystems, Inc.
57 * General purpose routine to see how much space something will use
58 * when serialized using XDR.
66 sec_x_putlong(xdrs
, intp
)
70 xdrs
->x_handy
+= BYTES_PER_XDR_UNIT
;
76 sec_x_putbytes(xdrs
, bp
, len
)
89 return (xdrs
->x_handy
);
94 sec_x_setpostn(xdrs
, pos
)
98 /* This is not allowed */
103 sec_x_inline(xdrs
, len
)
113 if (xdrs
->x_op
!= XDR_ENCODE
) {
119 if (llen
< (intptr_t)xdrs
->x_base
) {
120 /* x_private was already allocated */
121 xdrs
->x_handy
+= llen
;
122 return ((int32_t *) xdrs
->x_private
);
124 /* Free the earlier space and allocate new area */
126 free(xdrs
->x_private
);
127 if ((xdrs
->x_private
= (caddr_t
) malloc(len
)) == NULL
) {
131 xdrs
->x_base
= (caddr_t
)llen
;
132 xdrs
->x_handy
+= llen
;
133 return ((int32_t *) xdrs
->x_private
);
140 /* Always return FALSE/NULL, as the case may be */
150 if (xdrs
->x_private
) {
151 free(xdrs
->x_private
);
152 xdrs
->x_private
= NULL
;
158 sec_xdr_sizeof_in(func
, data
)
165 /* to stop ANSI-C compiler from complaining */
167 typedef bool_t (* dummyfunc1
)(XDR
*, int *);
169 typedef bool_t (* dummyfunc1
)(XDR
*, long *);
171 typedef bool_t (* dummyfunc2
)(XDR
*, caddr_t
, u_int
);
173 ops
.x_putlong
= sec_x_putlong
;
174 ops
.x_putbytes
= sec_x_putbytes
;
175 ops
.x_inline
= sec_x_inline
;
176 ops
.x_getpostn
= sec_x_getpostn
;
177 ops
.x_setpostn
= sec_x_setpostn
;
178 ops
.x_destroy
= sec_x_destroy
;
180 /* the other harmless ones */
181 ops
.x_getlong
= (dummyfunc1
) sec_harmless
;
182 ops
.x_getbytes
= (dummyfunc2
) sec_harmless
;
187 x
.x_public
= (caddr_t
) NULL
; // explicitly unsetting to avoid confusion with custom allocator
188 x
.x_private
= (caddr_t
) NULL
;
189 x
.x_base
= (caddr_t
) 0;
191 sec_xdr_arena_allocator_t size_alloc
;
192 sec_xdr_arena_init_size_alloc(&size_alloc
, &x
);
193 stat
= func(&x
, data
, 0);
196 return (stat
== TRUE
? (unsigned) x
.x_handy
: 0);
200 sec_xdr_sizeof_out(copy
, size
, func
, data
)
209 sec_xdrmem_create(&x
, (void *)copy
, size
, XDR_DECODE
);
211 sec_xdr_arena_allocator_t size_alloc
;
212 sec_xdr_arena_init_size_alloc(&size_alloc
, &x
);
213 stat
= func(&x
, data
, 0);
215 free(size_alloc
.data
);
216 return (stat
== TRUE
? (u_int
)size_alloc
.offset
: 0);