]>
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
)
79 xdrs
->x_handy
+= BYTES_PER_XDR_UNIT
;
85 x_putbytes(xdrs
, bp
, len
)
98 return (xdrs
->x_handy
);
103 x_setpostn(xdrs
, pos
)
107 /* This is not allowed */
121 if (xdrs
->x_op
!= XDR_ENCODE
) {
127 if (llen
< (size_t)xdrs
->x_base
) {
128 /* x_private was already allocated */
129 xdrs
->x_handy
+= llen
;
130 return ((int32_t *) xdrs
->x_private
);
132 /* Free the earlier space and allocate new area */
134 free(xdrs
->x_private
);
135 if ((xdrs
->x_private
= (caddr_t
) malloc(len
)) == NULL
) {
139 xdrs
->x_base
= (caddr_t
)llen
;
140 xdrs
->x_handy
+= llen
;
141 return ((int32_t *) xdrs
->x_private
);
148 /* Always return FALSE/NULL, as the case may be */
158 if (xdrs
->x_private
) {
159 free(xdrs
->x_private
);
160 xdrs
->x_private
= NULL
;
170 xdr_sizeof(func
, data
)
177 /* to stop ANSI-C compiler from complaining */
179 typedef bool_t (* dummyfunc1
)(XDR
*, int *);
181 typedef bool_t (* dummyfunc1
)(XDR
*, long *);
183 typedef bool_t (* dummyfunc2
)(XDR
*, caddr_t
, u_int
);
185 ops
.x_putlong
= x_putlong
;
186 ops
.x_putbytes
= x_putbytes
;
187 ops
.x_inline
= x_inline
;
188 ops
.x_getpostn
= x_getpostn
;
189 ops
.x_setpostn
= x_setpostn
;
190 ops
.x_destroy
= x_destroy
;
192 /* the other harmless ones */
193 ops
.x_getlong
= (dummyfunc1
) harmless
;
194 ops
.x_getbytes
= (dummyfunc2
) harmless
;
199 x
.x_private
= (caddr_t
) NULL
;
200 x
.x_base
= (caddr_t
) 0;
202 stat
= func(&x
, data
);
205 return (stat
== TRUE
? (unsigned) x
.x_handy
: 0);