2 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
3 * unrestricted use provided that this legend is included on all tape
4 * media and as a part of the software program in whole or part. Users
5 * may copy or modify Sun RPC without charge, but are not authorized
6 * to license or distribute it to anyone else except as part of a product or
7 * program developed by the user.
9 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
10 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
11 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
13 * Sun RPC is provided with no support and without any obligation on the
14 * part of Sun Microsystems, Inc. to assist in its use, correction,
15 * modification or enhancement.
17 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
18 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
19 * OR ANY PART THEREOF.
21 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
22 * or profits or other special, indirect and consequential damages, even if
23 * Sun has been advised of the possibility of such damages.
25 * Sun Microsystems, Inc.
27 * Mountain View, California 94043
29 * $FreeBSD: src/lib/libc/xdr/xdr_sizeof.c,v 1.5 2003/03/07 13:19:40 nectar Exp $
30 * $DragonFly: src/lib/libc/xdr/xdr_sizeof.c,v 1.2 2005/12/05 00:47:57 swildner Exp $
36 * Copyright 1990 Sun Microsystems, Inc.
38 * General purpose routine to see how much space something will use
39 * when serialized using XDR.
42 #include "namespace.h"
43 #include <rpc/types.h>
45 #include <sys/types.h>
47 #include "un-namespace.h"
51 x_putlong(XDR
*xdrs
, long *longp __unused
)
53 xdrs
->x_handy
+= BYTES_PER_XDR_UNIT
;
59 x_putbytes(XDR
*xdrs
, char *bp __unused
, u_int len
)
68 return (xdrs
->x_handy
);
73 x_setpostn(XDR
*xdrs __unused
, u_int pos __unused
)
75 /* This is not allowed */
80 x_inline(XDR
*xdrs
, u_int len
)
85 if (xdrs
->x_op
!= XDR_ENCODE
) {
88 if (len
< (u_int
)xdrs
->x_base
) {
89 /* x_private was already allocated */
91 return ((int32_t *) xdrs
->x_private
);
93 /* Free the earlier space and allocate new area */
95 free(xdrs
->x_private
);
96 if ((xdrs
->x_private
= (caddr_t
) malloc(len
)) == NULL
) {
100 xdrs
->x_base
= (caddr_t
) len
;
101 xdrs
->x_handy
+= len
;
102 return ((int32_t *) xdrs
->x_private
);
109 /* Always return FALSE/NULL, as the case may be */
118 if (xdrs
->x_private
) {
119 free(xdrs
->x_private
);
120 xdrs
->x_private
= NULL
;
126 xdr_sizeof(xdrproc_t func
, void *data
)
131 /* to stop ANSI-C compiler from complaining */
132 typedef bool_t (* dummyfunc1
)(XDR
*, long *);
133 typedef bool_t (* dummyfunc2
)(XDR
*, caddr_t
, u_int
);
135 ops
.x_putlong
= x_putlong
;
136 ops
.x_putbytes
= x_putbytes
;
137 ops
.x_inline
= x_inline
;
138 ops
.x_getpostn
= x_getpostn
;
139 ops
.x_setpostn
= x_setpostn
;
140 ops
.x_destroy
= x_destroy
;
142 /* the other harmless ones */
143 ops
.x_getlong
= (dummyfunc1
) harmless
;
144 ops
.x_getbytes
= (dummyfunc2
) harmless
;
149 x
.x_private
= (caddr_t
) NULL
;
150 x
.x_base
= (caddr_t
) 0;
152 stat
= func(&x
, data
);
155 return (stat
== TRUE
? (unsigned) x
.x_handy
: 0);