]>
git.saurik.com Git - apple/libinfo.git/blob - rpc.subproj/xdr_sizeof.c
2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
7 * Reserved. This file contains Original Code and/or Modifications of
8 * Original Code as defined in and that are subject to the Apple Public
9 * Source License Version 1.1 (the "License"). You may not use this file
10 * except in compliance with the License. Please obtain a copy of the
11 * License at http://www.apple.com/publicsource and read it before using
14 * The Original Code and all software distributed under the License are
15 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT. Please see the
19 * License for the specific language governing rights and limitations
22 * @APPLE_LICENSE_HEADER_END@
26 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
27 * unrestricted use provided that this legend is included on all tape
28 * media and as a part of the software program in whole or part. Users
29 * may copy or modify Sun RPC without charge, but are not authorized
30 * to license or distribute it to anyone else except as part of a product or
31 * program developed by the user.
33 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
34 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
35 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
37 * Sun RPC is provided with no support and without any obligation on the
38 * part of Sun Microsystems, Inc. to assist in its use, correction,
39 * modification or enhancement.
41 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
42 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
43 * OR ANY PART THEREOF.
45 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
46 * or profits or other special, indirect and consequential damages, even if
47 * Sun has been advised of the possibility of such damages.
49 * Sun Microsystems, Inc.
51 * Mountain View, California 94043
56 * Copyright 1990 Sun Microsystems, Inc.
58 * General purpose routine to see how much space something will use
59 * when serialized using XDR.
62 #include <sys/cdefs.h>
64 #include <rpc/types.h>
66 #include <sys/types.h>
71 x_putlong(xdrs
, longp
)
75 xdrs
->x_handy
+= BYTES_PER_XDR_UNIT
;
81 x_putbytes(xdrs
, bp
, len
)
94 return (xdrs
->x_handy
);
103 /* This is not allowed */
117 if (xdrs
->x_op
!= XDR_ENCODE
) {
123 if (llen
< xdrs
->x_base
) {
124 /* x_private was already allocated */
125 xdrs
->x_handy
+= llen
;
126 return ((int32_t *) xdrs
->x_private
);
128 /* Free the earlier space and allocate new area */
130 free(xdrs
->x_private
);
131 if ((xdrs
->x_private
= (caddr_t
) malloc(len
)) == NULL
) {
135 xdrs
->x_base
= (caddr_t
)llen
;
136 xdrs
->x_handy
+= llen
;
137 return ((int32_t *) xdrs
->x_private
);
144 /* Always return FALSE/NULL, as the case may be */
154 if (xdrs
->x_private
) {
155 free(xdrs
->x_private
);
156 xdrs
->x_private
= NULL
;
162 xdr_sizeof(func
, data
)
169 /* to stop ANSI-C compiler from complaining */
170 typedef bool_t (* dummyfunc1
)(XDR
*, long *);
171 typedef bool_t (* dummyfunc2
)(XDR
*, caddr_t
, u_int
);
173 ops
.x_putlong
= x_putlong
;
174 ops
.x_putbytes
= x_putbytes
;
175 ops
.x_inline
= x_inline
;
176 ops
.x_getpostn
= x_getpostn
;
177 ops
.x_setpostn
= x_setpostn
;
178 ops
.x_destroy
= x_destroy
;
180 /* the other harmless ones */
181 ops
.x_getlong
= (dummyfunc1
) harmless
;
182 ops
.x_getbytes
= (dummyfunc2
) harmless
;
187 x
.x_private
= (caddr_t
) NULL
;
188 x
.x_base
= (caddr_t
) 0;
190 stat
= func(&x
, data
);
193 return (stat
== TRUE
? (unsigned) x
.x_handy
: 0);