Now update the XDR library.

Reviewed by: Mark Murray
This commit is contained in:
Bill Paul 1997-05-28 04:55:37 +00:00
parent 47593e96db
commit 7d0a5a3919
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/cvs2svn/branches/WPAUL/dist/; revision=26216
10 changed files with 641 additions and 216 deletions

View File

@ -1,11 +1,43 @@
# @(#)Makefile 5.11 (Berkeley) 9/6/90
.PATH: ${.CURDIR}/rpc ${.CURDIR}/.
CFLAGS+=-I${.CURDIR} -I${.CURDIR}/rpc
SRCS= xdr.c xdr_array.c xdr_mem.c \
xdr_rec.c xdr_reference.c xdr_stdio.c
.PATH: ${.CURDIR}/../libc/xdr ${.CURDIR}/.
SRCS+= xdr.c xdr_array.c xdr_float.c xdr_mem.c \
xdr_rec.c xdr_reference.c xdr_stdio.c xdr_sizeof.c
MAN3= xdr/xdr.3
UNSUPPORTED+= xdr_float.c
# Only build man pages with libc.
.if ${LIB} == "c"
MAN3+= xdr/xdr.3
MLINKS+= xdr.3 xdr_array.3 \
xdr.3 xdr_bool.3 \
xdr.3 xdr_bytes.3 \
xdr.3 xdr_char.3 \
xdr.3 xdr_destroy.3 \
xdr.3 xdr_double.3 \
xdr.3 xdr_enum.3 \
xdr.3 xdr_float.3 \
xdr.3 xdr_free.3 \
xdr.3 xdr_getpos.3 \
xdr.3 xdr_inline.3 \
xdr.3 xdr_int.3 \
xdr.3 xdr_long.3 \
xdr.3 xdrmem_create.3 \
xdr.3 xdr_opaque.3 \
xdr.3 xdr_pointer.3 \
xdr.3 xdrrec_create.3 \
xdr.3 xdrrec_endofrecord.3 \
xdr.3 xdrrec_eof.3 \
xdr.3 xdrrec_skiprecord.3 \
xdr.3 xdr_reference.3 \
xdr.3 xdr_setpos.3 \
xdr.3 xdr_short.3 \
xdr.3 xdrstdio_create.3 \
xdr.3 xdr_string.3 \
xdr.3 xdr_u_char.3 \
xdr.3 xdr_u_long.3 \
xdr.3 xdr_u_short.3 \
xdr.3 xdr_union.3 \
xdr.3 xdr_vector.3 \
xdr.3 xdr_void.3 \
xdr.3 xdr_wrapstring.3
.endif

View File

@ -1,5 +1,7 @@
.\" @(#)xdr.3n 2.2 88/08/03 4.0 RPCSRC; from 1.16 88/03/14 SMI
.TH XDR 3N "16 February 1988"
.\" $Id: xdr.3,v 1.3 1996/10/05 22:26:44 wosch Exp $
.\"
.TH XDR 3 "16 February 1988"
.SH NAME
xdr \- library routines for external data representation
.SH SYNOPSIS AND DESCRIPTION
@ -753,7 +755,7 @@ parameter
.I arrp
is the address of the pointer to the array, while
.I size
is is the element count of the array. The parameter
is the element count of the array. The parameter
.I elsize
is the
.I sizeof
@ -808,7 +810,7 @@ routines as parameters, and
one of the most frequently used primitives, requires three.
Returns one if it succeeds, zero otherwise.
.SH SEE ALSO
.BR rpc (3N)
.BR rpc (3)
.LP
The following manuals:
.RS

View File

@ -5,23 +5,23 @@
* may copy or modify Sun RPC without charge, but are not authorized
* to license or distribute it to anyone else except as part of a product or
* program developed by the user.
*
*
* SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
* WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
* PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
*
*
* Sun RPC is provided with no support and without any obligation on the
* part of Sun Microsystems, Inc. to assist in its use, correction,
* modification or enhancement.
*
*
* SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
* INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
* OR ANY PART THEREOF.
*
*
* In no event will Sun Microsystems, Inc. be liable for any lost revenue
* or profits or other special, indirect and consequential damages, even if
* Sun has been advised of the possibility of such damages.
*
*
* Sun Microsystems, Inc.
* 2550 Garcia Avenue
* Mountain View, California 94043
@ -30,7 +30,7 @@
#if defined(LIBC_SCCS) && !defined(lint)
/*static char *sccsid = "from: @(#)xdr.c 1.35 87/08/12";*/
/*static char *sccsid = "from: @(#)xdr.c 2.1 88/07/29 4.0 RPCSRC";*/
static char *rcsid = "$Id: xdr.c,v 1.1 1993/10/27 05:41:06 paul Exp $";
static char *rcsid = "$Id: xdr.c,v 1.4 1996/12/30 14:07:07 peter Exp $";
#endif
/*
@ -44,6 +44,8 @@ static char *rcsid = "$Id: xdr.c,v 1.1 1993/10/27 05:41:06 paul Exp $";
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <rpc/types.h>
#include <rpc/xdr.h>
@ -70,7 +72,7 @@ xdr_free(proc, objp)
char *objp;
{
XDR x;
x.x_op = XDR_FREE;
(*proc)(&x, objp);
}
@ -87,6 +89,7 @@ xdr_void(/* xdrs, addr */)
return (TRUE);
}
/*
* XDR integers
*/
@ -95,17 +98,25 @@ xdr_int(xdrs, ip)
XDR *xdrs;
int *ip;
{
long l;
#ifdef lint
(void) (xdr_short(xdrs, (short *)ip));
return (xdr_long(xdrs, (long *)ip));
#else
if (sizeof (int) == sizeof (long)) {
return (xdr_long(xdrs, (long *)ip));
} else {
return (xdr_short(xdrs, (short *)ip));
switch (xdrs->x_op) {
case XDR_ENCODE:
l = (long) *ip;
return (XDR_PUTLONG(xdrs, &l));
case XDR_DECODE:
if (!XDR_GETLONG(xdrs, &l)) {
return (FALSE);
}
*ip = (int) l;
return (TRUE);
case XDR_FREE:
return (TRUE);
}
#endif
return (FALSE);
}
/*
@ -116,19 +127,28 @@ xdr_u_int(xdrs, up)
XDR *xdrs;
u_int *up;
{
u_long l;
#ifdef lint
(void) (xdr_short(xdrs, (short *)up));
return (xdr_u_long(xdrs, (u_long *)up));
#else
if (sizeof (u_int) == sizeof (u_long)) {
return (xdr_u_long(xdrs, (u_long *)up));
} else {
return (xdr_short(xdrs, (short *)up));
switch (xdrs->x_op) {
case XDR_ENCODE:
l = (u_long) *up;
return (XDR_PUTLONG(xdrs, (long *)&l));
case XDR_DECODE:
if (!XDR_GETLONG(xdrs, (long *)&l)) {
return (FALSE);
}
*up = (u_int) l;
return (TRUE);
case XDR_FREE:
return (TRUE);
}
#endif
return (FALSE);
}
/*
* XDR long integers
* same as xdr_u_long - open coded to save a proc call!
@ -138,15 +158,14 @@ xdr_long(xdrs, lp)
register XDR *xdrs;
long *lp;
{
if (xdrs->x_op == XDR_ENCODE)
switch (xdrs->x_op) {
case XDR_ENCODE:
return (XDR_PUTLONG(xdrs, lp));
if (xdrs->x_op == XDR_DECODE)
case XDR_DECODE:
return (XDR_GETLONG(xdrs, lp));
if (xdrs->x_op == XDR_FREE)
case XDR_FREE:
return (TRUE);
}
return (FALSE);
}
@ -160,16 +179,79 @@ xdr_u_long(xdrs, ulp)
register XDR *xdrs;
u_long *ulp;
{
if (xdrs->x_op == XDR_DECODE)
return (XDR_GETLONG(xdrs, (long *)ulp));
if (xdrs->x_op == XDR_ENCODE)
switch (xdrs->x_op) {
case XDR_ENCODE:
return (XDR_PUTLONG(xdrs, (long *)ulp));
if (xdrs->x_op == XDR_FREE)
case XDR_DECODE:
return (XDR_GETLONG(xdrs, (long *)ulp));
case XDR_FREE:
return (TRUE);
}
return (FALSE);
}
/*
* XDR 32-bit integers
* same as xdr_u_int32_t - open coded to save a proc call!
*/
bool_t
xdr_int32_t(xdrs, int32_p)
register XDR *xdrs;
int32_t *int32_p;
{
long l;
switch (xdrs->x_op) {
case XDR_ENCODE:
l = (long) *int32_p;
return (XDR_PUTLONG(xdrs, &l));
case XDR_DECODE:
if (!XDR_GETLONG(xdrs, &l)) {
return (FALSE);
}
*int32_p = (int32_t) l;
return (TRUE);
case XDR_FREE:
return (TRUE);
}
return (FALSE);
}
/*
* XDR unsigned 32-bit integers
* same as xdr_int32_t - open coded to save a proc call!
*/
bool_t
xdr_u_int32_t(xdrs, u_int32_p)
register XDR *xdrs;
u_int32_t *u_int32_p;
{
u_long l;
switch (xdrs->x_op) {
case XDR_ENCODE:
l = (u_long) *u_int32_p;
return (XDR_PUTLONG(xdrs, (long *)&l));
case XDR_DECODE:
if (!XDR_GETLONG(xdrs, (long *)&l)) {
return (FALSE);
}
*u_int32_p = (u_int32_t) l;
return (TRUE);
case XDR_FREE:
return (TRUE);
}
return (FALSE);
}
/*
* XDR short integers
*/
@ -213,13 +295,72 @@ xdr_u_short(xdrs, usp)
case XDR_ENCODE:
l = (u_long) *usp;
return (XDR_PUTLONG(xdrs, (long *)&l));
case XDR_DECODE:
if (!XDR_GETLONG(xdrs, (long *)&l)) {
return (FALSE);
}
*usp = (u_short) l;
return (TRUE);
case XDR_FREE:
return (TRUE);
}
return (FALSE);
}
/*
* XDR 16-bit integers
*/
bool_t
xdr_int16_t(xdrs, int16_p)
register XDR *xdrs;
int16_t *int16_p;
{
long l;
switch (xdrs->x_op) {
case XDR_ENCODE:
l = (long) *int16_p;
return (XDR_PUTLONG(xdrs, &l));
case XDR_DECODE:
if (!XDR_GETLONG(xdrs, &l)) {
return (FALSE);
}
*usp = (u_short) l;
*int16_p = (int16_t) l;
return (TRUE);
case XDR_FREE:
return (TRUE);
}
return (FALSE);
}
/*
* XDR unsigned 16-bit integers
*/
bool_t
xdr_u_int16_t(xdrs, u_int16_p)
register XDR *xdrs;
u_int16_t *u_int16_p;
{
u_long l;
switch (xdrs->x_op) {
case XDR_ENCODE:
l = (u_long) *u_int16_p;
return (XDR_PUTLONG(xdrs, (long *)&l));
case XDR_DECODE:
if (!XDR_GETLONG(xdrs, (long *)&l)) {
return (FALSE);
}
*u_int16_p = (u_int16_t) l;
return (TRUE);
case XDR_FREE:
@ -253,7 +394,7 @@ xdr_char(xdrs, cp)
bool_t
xdr_u_char(xdrs, cp)
XDR *xdrs;
char *cp;
u_char *cp;
{
u_int u;
@ -310,6 +451,8 @@ xdr_enum(xdrs, ep)
*/
if (sizeof (enum sizecheck) == sizeof (long)) {
return (xdr_long(xdrs, (long *)ep));
} else if (sizeof (enum sizecheck) == sizeof (int)) {
return (xdr_int(xdrs, (int *)ep));
} else if (sizeof (enum sizecheck) == sizeof (short)) {
return (xdr_short(xdrs, (short *)ep));
} else {
@ -317,6 +460,7 @@ xdr_enum(xdrs, ep)
}
#else
(void) (xdr_short(xdrs, (short *)ep));
(void) (xdr_int(xdrs, (int *)ep));
return (xdr_long(xdrs, (long *)ep));
#endif
}
@ -354,7 +498,7 @@ xdr_opaque(xdrs, cp, cnt)
}
if (rndup == 0)
return (TRUE);
return (XDR_GETBYTES(xdrs, crud, rndup));
return (XDR_GETBYTES(xdrs, (caddr_t)crud, rndup));
}
if (xdrs->x_op == XDR_ENCODE) {
@ -562,8 +706,8 @@ xdr_string(xdrs, cpp, maxsize)
return (FALSE);
}
/*
* Wrapper for xdr_string that can be called directly from
/*
* Wrapper for xdr_string that can be called directly from
* routines like clnt_call
*/
bool_t
@ -571,8 +715,5 @@ xdr_wrapstring(xdrs, cpp)
XDR *xdrs;
char **cpp;
{
if (xdr_string(xdrs, cpp, LASTUNSIGNED)) {
return (TRUE);
}
return (FALSE);
return xdr_string(xdrs, cpp, LASTUNSIGNED);
}

View File

@ -5,23 +5,23 @@
* may copy or modify Sun RPC without charge, but are not authorized
* to license or distribute it to anyone else except as part of a product or
* program developed by the user.
*
*
* SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
* WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
* PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
*
*
* Sun RPC is provided with no support and without any obligation on the
* part of Sun Microsystems, Inc. to assist in its use, correction,
* modification or enhancement.
*
*
* SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
* INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
* OR ANY PART THEREOF.
*
*
* In no event will Sun Microsystems, Inc. be liable for any lost revenue
* or profits or other special, indirect and consequential damages, even if
* Sun has been advised of the possibility of such damages.
*
*
* Sun Microsystems, Inc.
* 2550 Garcia Avenue
* Mountain View, California 94043
@ -30,7 +30,7 @@
#if defined(LIBC_SCCS) && !defined(lint)
/*static char *sccsid = "from: @(#)xdr_array.c 1.10 87/08/11 Copyr 1984 Sun Micro";*/
/*static char *sccsid = "from: @(#)xdr_array.c 2.1 88/07/29 4.0 RPCSRC";*/
static char *rcsid = "$Id: xdr_array.c,v 1.1 1993/10/27 05:41:09 paul Exp $";
static char *rcsid = "$Id: xdr_array.c,v 1.4 1996/12/30 14:07:08 peter Exp $";
#endif
/*
@ -44,11 +44,11 @@ static char *rcsid = "$Id: xdr_array.c,v 1.1 1993/10/27 05:41:09 paul Exp $";
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <rpc/types.h>
#include <rpc/xdr.h>
#define LASTUNSIGNED ((u_int)0-1)
#define LASTUNSIGNED ((u_int) 0-1)
/*
* XDR an array of arbitrary elements
@ -93,17 +93,17 @@ xdr_array(xdrs, addrp, sizep, maxsize, elsize, elproc)
return (TRUE);
*addrp = target = mem_alloc(nodesize);
if (target == NULL) {
(void) fprintf(stderr,
(void) fprintf(stderr,
"xdr_array: out of memory\n");
return (FALSE);
}
bzero(target, nodesize);
memset(target, 0, nodesize);
break;
case XDR_FREE:
return (TRUE);
}
/*
* now we xdr each element of array
*/
@ -138,7 +138,7 @@ xdr_vector(xdrs, basep, nelem, elemsize, xdr_elem)
register char *basep;
register u_int nelem;
register u_int elemsize;
register xdrproc_t xdr_elem;
register xdrproc_t xdr_elem;
{
register u_int i;
register char *elptr;
@ -150,6 +150,6 @@ xdr_vector(xdrs, basep, nelem, elemsize, xdr_elem)
}
elptr += elemsize;
}
return(TRUE);
return(TRUE);
}

View File

@ -5,23 +5,23 @@
* may copy or modify Sun RPC without charge, but are not authorized
* to license or distribute it to anyone else except as part of a product or
* program developed by the user.
*
*
* SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
* WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
* PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
*
*
* Sun RPC is provided with no support and without any obligation on the
* part of Sun Microsystems, Inc. to assist in its use, correction,
* modification or enhancement.
*
*
* SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
* INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
* OR ANY PART THEREOF.
*
*
* In no event will Sun Microsystems, Inc. be liable for any lost revenue
* or profits or other special, indirect and consequential damages, even if
* Sun has been advised of the possibility of such damages.
*
*
* Sun Microsystems, Inc.
* 2550 Garcia Avenue
* Mountain View, California 94043
@ -30,7 +30,7 @@
#if defined(LIBC_SCCS) && !defined(lint)
/*static char *sccsid = "from: @(#)xdr_float.c 1.12 87/08/11 Copyr 1984 Sun Micro";*/
/*static char *sccsid = "from: @(#)xdr_float.c 2.1 88/07/29 4.0 RPCSRC";*/
static char *rcsid = "$Id: xdr_float.c,v 1.1 1993/10/27 05:41:10 paul Exp $";
static char *rcsid = "$Id: xdr_float.c,v 1.3 1996/12/30 14:07:08 peter Exp $";
#endif
/*
@ -51,10 +51,13 @@ static char *rcsid = "$Id: xdr_float.c,v 1.1 1993/10/27 05:41:10 paul Exp $";
/*
* NB: Not portable.
* This routine works on Suns (Sky / 68000's), i386's, MIPS, NS32k and Vaxen.
* This routine works on machines with IEEE754 FP and Vaxen.
*/
#if defined(mc68000)||defined(sparc)||defined(i386)||defined(mips)||defined(ns32000)
#if defined(__m68k__) || defined(__sparc__) || defined(__i386__) || \
defined(__mips__) || defined(__ns32k__) || defined(__alpha__) || \
defined(__arm32__) || defined(__ppc__)
#include <machine/endian.h>
#define IEEEFP
#endif
@ -94,7 +97,10 @@ xdr_float(xdrs, fp)
register XDR *xdrs;
register float *fp;
{
#ifndef IEEEFP
#ifdef IEEEFP
bool_t rv;
long tmpl;
#else
struct ieee_single is;
struct vax_single vs, *vsp;
struct sgl_limits *lim;
@ -103,8 +109,9 @@ xdr_float(xdrs, fp)
switch (xdrs->x_op) {
case XDR_ENCODE:
#ifdef IEEEFP
return (XDR_PUTLONG(xdrs, (long *)fp));
#ifdef IEEEFP
tmpl = *(int32_t *)fp;
return (XDR_PUTLONG(xdrs, &tmpl));
#else
vs = *((struct vax_single *)fp);
for (i = 0, lim = sgl_limits;
@ -126,7 +133,9 @@ xdr_float(xdrs, fp)
case XDR_DECODE:
#ifdef IEEEFP
return (XDR_GETLONG(xdrs, (long *)fp));
rv = XDR_GETLONG(xdrs, &tmpl);
*(int32_t *)fp = tmpl;
return (rv);
#else
vsp = (struct vax_single *)fp;
if (!XDR_GETLONG(xdrs, (long *)&is))
@ -154,10 +163,6 @@ xdr_float(xdrs, fp)
return (FALSE);
}
/*
* This routine works on Suns (Sky / 68000's), i386's, MIPS and Vaxen.
*/
#ifdef vax
/* What IEEE double precision floating point looks like on a Vax */
struct ieee_double {
@ -199,8 +204,12 @@ xdr_double(xdrs, dp)
register XDR *xdrs;
double *dp;
{
#ifdef IEEEFP
register int32_t *i32p;
bool_t rv;
long tmpl;
#else
register long *lp;
#ifndef IEEEFP
struct ieee_double id;
struct vax_double vd;
register struct dbl_limits *lim;
@ -211,12 +220,23 @@ xdr_double(xdrs, dp)
case XDR_ENCODE:
#ifdef IEEEFP
lp = (long *)dp;
i32p = (int32_t *)dp;
#if BYTE_ORDER == BIG_ENDIAN
return (XDR_PUTLONG(xdrs, lp++) && XDR_PUTLONG(xdrs, lp));
tmpl = *i32p++;
rv = XDR_PUTLONG(xdrs, &tmpl);
if (!rv)
return (rv);
tmpl = *i32p;
rv = XDR_PUTLONG(xdrs, &tmpl);
#else
return (XDR_PUTLONG(xdrs, lp+1) && XDR_PUTLONG(xdrs, lp));
tmpl = *(i32p+1);
rv = XDR_PUTLONG(xdrs, &tmpl);
if (!rv)
return (rv);
tmpl = *i32p;
rv = XDR_PUTLONG(xdrs, &tmpl);
#endif
return (rv);
#else
vd = *((struct vax_double *)dp);
for (i = 0, lim = dbl_limits;
@ -244,12 +264,23 @@ xdr_double(xdrs, dp)
case XDR_DECODE:
#ifdef IEEEFP
lp = (long *)dp;
i32p = (int32_t *)dp;
#if BYTE_ORDER == BIG_ENDIAN
return (XDR_GETLONG(xdrs, lp++) && XDR_GETLONG(xdrs, lp));
rv = XDR_GETLONG(xdrs, &tmpl);
*i32p++ = tmpl;
if (!rv)
return (rv);
rv = XDR_GETLONG(xdrs, &tmpl);
*i32p = tmpl;
#else
return (XDR_GETLONG(xdrs, lp+1) && XDR_GETLONG(xdrs, lp));
rv = XDR_GETLONG(xdrs, &tmpl);
*(i32p+1) = tmpl;
if (!rv)
return (rv);
rv = XDR_GETLONG(xdrs, &tmpl);
*i32p = tmpl;
#endif
return (rv);
#else
lp = (long *)&id;
if (!XDR_GETLONG(xdrs, lp++) || !XDR_GETLONG(xdrs, lp))

View File

@ -5,23 +5,23 @@
* may copy or modify Sun RPC without charge, but are not authorized
* to license or distribute it to anyone else except as part of a product or
* program developed by the user.
*
*
* SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
* WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
* PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
*
*
* Sun RPC is provided with no support and without any obligation on the
* part of Sun Microsystems, Inc. to assist in its use, correction,
* modification or enhancement.
*
*
* SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
* INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
* OR ANY PART THEREOF.
*
*
* In no event will Sun Microsystems, Inc. be liable for any lost revenue
* or profits or other special, indirect and consequential damages, even if
* Sun has been advised of the possibility of such damages.
*
*
* Sun Microsystems, Inc.
* 2550 Garcia Avenue
* Mountain View, California 94043
@ -30,7 +30,7 @@
#if defined(LIBC_SCCS) && !defined(lint)
/*static char *sccsid = "from: @(#)xdr_mem.c 1.19 87/08/11 Copyr 1984 Sun Micro";*/
/*static char *sccsid = "from: @(#)xdr_mem.c 2.1 88/07/29 4.0 RPCSRC";*/
static char *rcsid = "$Id: xdr_mem.c,v 1.1 1993/10/27 05:41:11 paul Exp $";
static char *rcsid = "$Id: xdr_mem.c,v 1.4 1996/12/30 14:07:09 peter Exp $";
#endif
/*
@ -44,34 +44,48 @@ static char *rcsid = "$Id: xdr_mem.c,v 1.1 1993/10/27 05:41:11 paul Exp $";
*
*/
#include <string.h>
#include <rpc/types.h>
#include <rpc/xdr.h>
#include <netinet/in.h>
static bool_t xdrmem_getlong();
static bool_t xdrmem_putlong();
static bool_t xdrmem_getlong_aligned();
static bool_t xdrmem_putlong_aligned();
static bool_t xdrmem_getlong_unaligned();
static bool_t xdrmem_putlong_unaligned();
static bool_t xdrmem_getbytes();
static bool_t xdrmem_putbytes();
static u_int xdrmem_getpos();
static u_int xdrmem_getpos(); /* XXX w/64-bit pointers, u_int not enough! */
static bool_t xdrmem_setpos();
static long * xdrmem_inline();
static int32_t *xdrmem_inline_aligned();
static int32_t *xdrmem_inline_unaligned();
static void xdrmem_destroy();
static struct xdr_ops xdrmem_ops = {
xdrmem_getlong,
xdrmem_putlong,
static struct xdr_ops xdrmem_ops_aligned = {
xdrmem_getlong_aligned,
xdrmem_putlong_aligned,
xdrmem_getbytes,
xdrmem_putbytes,
xdrmem_getpos,
xdrmem_setpos,
xdrmem_inline,
xdrmem_inline_aligned,
xdrmem_destroy
};
static struct xdr_ops xdrmem_ops_unaligned = {
xdrmem_getlong_unaligned,
xdrmem_putlong_unaligned,
xdrmem_getbytes,
xdrmem_putbytes,
xdrmem_getpos,
xdrmem_setpos,
xdrmem_inline_unaligned,
xdrmem_destroy
};
/*
* The procedure xdrmem_create initializes a stream descriptor for a
* memory buffer.
* memory buffer.
*/
void
xdrmem_create(xdrs, addr, size, op)
@ -82,7 +96,8 @@ xdrmem_create(xdrs, addr, size, op)
{
xdrs->x_op = op;
xdrs->x_ops = &xdrmem_ops;
xdrs->x_ops = ((size_t)addr & (sizeof(int32_t) - 1))
? &xdrmem_ops_unaligned : &xdrmem_ops_aligned;
xdrs->x_private = xdrs->x_base = addr;
xdrs->x_handy = size;
}
@ -91,31 +106,62 @@ static void
xdrmem_destroy(/*xdrs*/)
/*XDR *xdrs;*/
{
}
static bool_t
xdrmem_getlong(xdrs, lp)
xdrmem_getlong_aligned(xdrs, lp)
register XDR *xdrs;
long *lp;
{
if ((xdrs->x_handy -= sizeof(long)) < 0)
if ((xdrs->x_handy -= sizeof(int32_t)) < 0)
return (FALSE);
*lp = (long)ntohl((u_long)(*((long *)(xdrs->x_private))));
xdrs->x_private += sizeof(long);
*lp = ntohl(*(int32_t *)(xdrs->x_private));
xdrs->x_private += sizeof(int32_t);
return (TRUE);
}
static bool_t
xdrmem_putlong(xdrs, lp)
xdrmem_putlong_aligned(xdrs, lp)
register XDR *xdrs;
long *lp;
{
if ((xdrs->x_handy -= sizeof(long)) < 0)
if ((xdrs->x_handy -= sizeof(int32_t)) < 0)
return (FALSE);
*(long *)xdrs->x_private = (long)htonl((u_long)(*lp));
xdrs->x_private += sizeof(long);
*(int32_t *)xdrs->x_private = htonl(*lp);
xdrs->x_private += sizeof(int32_t);
return (TRUE);
}
static bool_t
xdrmem_getlong_unaligned(xdrs, lp)
register XDR *xdrs;
long *lp;
{
int32_t l;
if ((xdrs->x_handy -= sizeof(int32_t)) < 0)
return (FALSE);
memcpy(&l, xdrs->x_private, sizeof(int32_t));
*lp = ntohl(l);
xdrs->x_private += sizeof(int32_t);
return (TRUE);
}
static bool_t
xdrmem_putlong_unaligned(xdrs, lp)
register XDR *xdrs;
long *lp;
{
int32_t l;
if ((xdrs->x_handy -= sizeof(int32_t)) < 0)
return (FALSE);
l = htonl(*lp);
memcpy(xdrs->x_private, &l, sizeof(int32_t));
xdrs->x_private += sizeof(int32_t);
return (TRUE);
}
@ -128,7 +174,7 @@ xdrmem_getbytes(xdrs, addr, len)
if ((xdrs->x_handy -= len) < 0)
return (FALSE);
bcopy(xdrs->x_private, addr, len);
memcpy(addr, xdrs->x_private, len);
xdrs->x_private += len;
return (TRUE);
}
@ -142,7 +188,7 @@ xdrmem_putbytes(xdrs, addr, len)
if ((xdrs->x_handy -= len) < 0)
return (FALSE);
bcopy(addr, xdrs->x_private, len);
memcpy(xdrs->x_private, addr, len);
xdrs->x_private += len;
return (TRUE);
}
@ -152,7 +198,8 @@ xdrmem_getpos(xdrs)
register XDR *xdrs;
{
return ((u_int)xdrs->x_private - (u_int)xdrs->x_base);
/* XXX w/64-bit pointers, u_int not enough! */
return ((u_long)xdrs->x_private - (u_long)xdrs->x_base);
}
static bool_t
@ -166,21 +213,30 @@ xdrmem_setpos(xdrs, pos)
if ((long)newaddr > (long)lastaddr)
return (FALSE);
xdrs->x_private = newaddr;
xdrs->x_handy = (int)lastaddr - (int)newaddr;
xdrs->x_handy = (long)lastaddr - (long)newaddr;
return (TRUE);
}
static long *
xdrmem_inline(xdrs, len)
static int32_t *
xdrmem_inline_aligned(xdrs, len)
register XDR *xdrs;
int len;
{
long *buf = 0;
int32_t *buf = 0;
if (xdrs->x_handy >= len) {
xdrs->x_handy -= len;
buf = (long *) xdrs->x_private;
buf = (int32_t *) xdrs->x_private;
xdrs->x_private += len;
}
return (buf);
}
static int32_t *
xdrmem_inline_unaligned(xdrs, len)
register XDR *xdrs;
int len;
{
return (0);
}

View File

@ -5,31 +5,31 @@
* may copy or modify Sun RPC without charge, but are not authorized
* to license or distribute it to anyone else except as part of a product or
* program developed by the user.
*
*
* SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
* WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
* PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
*
*
* Sun RPC is provided with no support and without any obligation on the
* part of Sun Microsystems, Inc. to assist in its use, correction,
* modification or enhancement.
*
*
* SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
* INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
* OR ANY PART THEREOF.
*
*
* In no event will Sun Microsystems, Inc. be liable for any lost revenue
* or profits or other special, indirect and consequential damages, even if
* Sun has been advised of the possibility of such damages.
*
*
* Sun Microsystems, Inc.
* 2550 Garcia Avenue
* Mountain View, California 94043
*/
#if defined(LIBC_SCCS) && !defined(lint)
#if defined(LIBC_SCCS) && !defined(lint)
/*static char *sccsid = "from: @(#)xdr_rec.c 1.21 87/08/11 Copyr 1984 Sun Micro";*/
/*static char *sccsid = "from: @(#)xdr_rec.c 2.2 88/08/01 4.0 RPCSRC";*/
static char *rcsid = "$Id: xdr_rec.c,v 1.1 1993/10/27 05:41:12 paul Exp $";
static char *rcsid = "$Id: xdr_rec.c,v 1.5 1996/12/30 14:07:10 peter Exp $";
#endif
/*
@ -45,18 +45,17 @@ static char *rcsid = "$Id: xdr_rec.c,v 1.1 1993/10/27 05:41:12 paul Exp $";
* by n bytes of data, where n is contained in the header. The header
* is represented as a htonl(u_long). Thegh order bit encodes
* whether or not the fragment is the last fragment of the record
* (1 => fragment is last, 0 => more fragments to follow.
* (1 => fragment is last, 0 => more fragments to follow.
* The other 31 bits encode the byte length of the fragment.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <rpc/types.h>
#include <rpc/xdr.h>
#include <netinet/in.h>
extern long lseek();
static u_int fix_buf_size();
static bool_t flush_out();
static bool_t get_input_bytes();
@ -69,7 +68,7 @@ static bool_t xdrrec_getbytes();
static bool_t xdrrec_putbytes();
static u_int xdrrec_getpos();
static bool_t xdrrec_setpos();
static long * xdrrec_inline();
static int32_t *xdrrec_inline();
static void xdrrec_destroy();
static struct xdr_ops xdrrec_ops = {
@ -96,7 +95,7 @@ static struct xdr_ops xdrrec_ops = {
* meet the needs of xdr and rpc based on tcp.
*/
#define LAST_FRAG ((u_long)(1 << 31))
#define LAST_FRAG ((u_int32_t)(1 << 31))
typedef struct rec_strm {
caddr_t tcp_handle;
@ -104,16 +103,16 @@ typedef struct rec_strm {
/*
* out-goung bits
*/
int (*writeit)();
int (*writeit) __P((caddr_t, caddr_t, int));
caddr_t out_base; /* output buffer (points to frag header) */
caddr_t out_finger; /* next output position */
caddr_t out_boundry; /* data cannot up to this address */
u_long *frag_header; /* beginning of curren fragment */
u_int32_t *frag_header; /* beginning of current fragment */
bool_t frag_sent; /* true if buffer sent in middle of record */
/*
* in-coming bits
*/
int (*readit)();
int (*readit) __P((caddr_t, caddr_t, int));
u_long in_size; /* fixed size of the input buffer */
caddr_t in_base;
caddr_t in_finger; /* location of next byte to be had */
@ -148,8 +147,8 @@ xdrrec_create(xdrs, sendsize, recvsize, tcp_handle, readit, writeit)
if (rstrm == NULL) {
(void)fprintf(stderr, "xdrrec_create: out of memory\n");
/*
* This is bad. Should rework xdrrec_create to
/*
* This is bad. Should rework xdrrec_create to
* return a handle, and in this case return NULL
*/
return;
@ -165,7 +164,7 @@ xdrrec_create(xdrs, sendsize, recvsize, tcp_handle, readit, writeit)
return;
}
for (rstrm->out_base = rstrm->the_buffer;
(u_int)rstrm->out_base % BYTES_PER_XDR_UNIT != 0;
(u_long)rstrm->out_base % BYTES_PER_XDR_UNIT != 0;
rstrm->out_base++);
rstrm->in_base = rstrm->out_base + sendsize;
/*
@ -177,8 +176,8 @@ xdrrec_create(xdrs, sendsize, recvsize, tcp_handle, readit, writeit)
rstrm->readit = readit;
rstrm->writeit = writeit;
rstrm->out_finger = rstrm->out_boundry = rstrm->out_base;
rstrm->frag_header = (u_long *)rstrm->out_base;
rstrm->out_finger += sizeof(u_long);
rstrm->frag_header = (u_int32_t *)rstrm->out_base;
rstrm->out_finger += sizeof(u_int32_t);
rstrm->out_boundry += sendsize;
rstrm->frag_sent = FALSE;
rstrm->in_size = recvsize;
@ -200,19 +199,19 @@ xdrrec_getlong(xdrs, lp)
long *lp;
{
register RECSTREAM *rstrm = (RECSTREAM *)(xdrs->x_private);
register long *buflp = (long *)(rstrm->in_finger);
long mylong;
register int32_t *buflp = (int32_t *)(rstrm->in_finger);
int32_t mylong;
/* first try the inline, fast case */
if ((rstrm->fbtbc >= sizeof(long)) &&
(((int)rstrm->in_boundry - (int)buflp) >= sizeof(long))) {
*lp = (long)ntohl((u_long)(*buflp));
rstrm->fbtbc -= sizeof(long);
rstrm->in_finger += sizeof(long);
if ((rstrm->fbtbc >= sizeof(int32_t)) &&
(((long)rstrm->in_boundry - (long)buflp) >= sizeof(int32_t))) {
*lp = (long)ntohl((u_int32_t)(*buflp));
rstrm->fbtbc -= sizeof(int32_t);
rstrm->in_finger += sizeof(int32_t);
} else {
if (! xdrrec_getbytes(xdrs, (caddr_t)&mylong, sizeof(long)))
if (! xdrrec_getbytes(xdrs, (caddr_t)&mylong, sizeof(int32_t)))
return (FALSE);
*lp = (long)ntohl((u_long)mylong);
*lp = (long)ntohl((u_int32_t)mylong);
}
return (TRUE);
}
@ -223,21 +222,21 @@ xdrrec_putlong(xdrs, lp)
long *lp;
{
register RECSTREAM *rstrm = (RECSTREAM *)(xdrs->x_private);
register long *dest_lp = ((long *)(rstrm->out_finger));
register int32_t *dest_lp = ((int32_t *)(rstrm->out_finger));
if ((rstrm->out_finger += sizeof(long)) > rstrm->out_boundry) {
if ((rstrm->out_finger += sizeof(int32_t)) > rstrm->out_boundry) {
/*
* this case should almost never happen so the code is
* inefficient
*/
rstrm->out_finger -= sizeof(long);
rstrm->out_finger -= sizeof(int32_t);
rstrm->frag_sent = TRUE;
if (! flush_out(rstrm, FALSE))
return (FALSE);
dest_lp = ((long *)(rstrm->out_finger));
rstrm->out_finger += sizeof(long);
dest_lp = ((int32_t *)(rstrm->out_finger));
rstrm->out_finger += sizeof(int32_t);
}
*dest_lp = (long)htonl((u_long)(*lp));
*dest_lp = (int32_t)htonl((u_int32_t)(*lp));
return (TRUE);
}
@ -262,7 +261,7 @@ xdrrec_getbytes(xdrs, addr, len)
current = (len < current) ? len : current;
if (! get_input_bytes(rstrm, addr, current))
return (FALSE);
addr += current;
addr += current;
rstrm->fbtbc -= current;
len -= current;
}
@ -276,12 +275,13 @@ xdrrec_putbytes(xdrs, addr, len)
register u_int len;
{
register RECSTREAM *rstrm = (RECSTREAM *)(xdrs->x_private);
register int current;
register long current;
while (len > 0) {
current = (u_int)rstrm->out_boundry - (u_int)rstrm->out_finger;
current = (u_long)rstrm->out_boundry -
(u_long)rstrm->out_finger;
current = (len < current) ? len : current;
bcopy(addr, rstrm->out_finger, current);
memcpy(rstrm->out_finger, addr, current);
rstrm->out_finger += current;
addr += current;
len -= current;
@ -301,7 +301,7 @@ xdrrec_getpos(xdrs)
register RECSTREAM *rstrm = (RECSTREAM *)xdrs->x_private;
register long pos;
pos = lseek((int)rstrm->tcp_handle, (long) 0, 1);
pos = lseek((int)(long)rstrm->tcp_handle, (off_t) 0, 1);
if (pos != -1)
switch (xdrs->x_op) {
@ -314,7 +314,7 @@ xdrrec_getpos(xdrs)
break;
default:
pos = (u_int) -1;
pos = -1;
break;
}
return ((u_int) pos);
@ -356,19 +356,19 @@ xdrrec_setpos(xdrs, pos)
return (FALSE);
}
static long *
static int32_t *
xdrrec_inline(xdrs, len)
register XDR *xdrs;
int len;
{
register RECSTREAM *rstrm = (RECSTREAM *)xdrs->x_private;
long * buf = NULL;
int32_t * buf = NULL;
switch (xdrs->x_op) {
case XDR_ENCODE:
if ((rstrm->out_finger + len) <= rstrm->out_boundry) {
buf = (long *) rstrm->out_finger;
buf = (int32_t *) rstrm->out_finger;
rstrm->out_finger += len;
}
break;
@ -376,7 +376,7 @@ xdrrec_inline(xdrs, len)
case XDR_DECODE:
if ((len <= rstrm->fbtbc) &&
((rstrm->in_finger + len) <= rstrm->in_boundry)) {
buf = (long *) rstrm->in_finger;
buf = (int32_t *) rstrm->in_finger;
rstrm->fbtbc -= len;
rstrm->in_finger += len;
}
@ -424,7 +424,7 @@ xdrrec_skiprecord(xdrs)
/*
* Look ahead fuction.
* Returns TRUE iff there is no more input in the buffer
* Returns TRUE iff there is no more input in the buffer
* after consuming the rest of the current record.
*/
bool_t
@ -460,16 +460,16 @@ xdrrec_endofrecord(xdrs, sendnow)
register u_long len; /* fragment length */
if (sendnow || rstrm->frag_sent ||
((u_long)rstrm->out_finger + sizeof(u_long) >=
((u_long)rstrm->out_finger + sizeof(u_int32_t) >=
(u_long)rstrm->out_boundry)) {
rstrm->frag_sent = FALSE;
return (flush_out(rstrm, TRUE));
}
len = (u_long)(rstrm->out_finger) - (u_long)(rstrm->frag_header) -
sizeof(u_long);
sizeof(u_int32_t);
*(rstrm->frag_header) = htonl((u_long)len | LAST_FRAG);
rstrm->frag_header = (u_long *)rstrm->out_finger;
rstrm->out_finger += sizeof(u_long);
rstrm->frag_header = (u_int32_t *)rstrm->out_finger;
rstrm->out_finger += sizeof(u_int32_t);
return (TRUE);
}
@ -483,16 +483,16 @@ flush_out(rstrm, eor)
bool_t eor;
{
register u_long eormask = (eor == TRUE) ? LAST_FRAG : 0;
register u_long len = (u_long)(rstrm->out_finger) -
(u_long)(rstrm->frag_header) - sizeof(u_long);
register u_int32_t len = (u_long)(rstrm->out_finger) -
(u_long)(rstrm->frag_header) - sizeof(u_int32_t);
*(rstrm->frag_header) = htonl(len | eormask);
len = (u_long)(rstrm->out_finger) - (u_long)(rstrm->out_base);
if ((*(rstrm->writeit))(rstrm->tcp_handle, rstrm->out_base, (int)len)
!= (int)len)
return (FALSE);
rstrm->frag_header = (u_long *)rstrm->out_base;
rstrm->out_finger = (caddr_t)rstrm->out_base + sizeof(u_long);
rstrm->frag_header = (u_int32_t *)rstrm->out_base;
rstrm->out_finger = (caddr_t)rstrm->out_base + sizeof(u_int32_t);
return (TRUE);
}
@ -501,11 +501,11 @@ fill_input_buf(rstrm)
register RECSTREAM *rstrm;
{
register caddr_t where;
u_int i;
register int len;
u_long i;
register long len;
where = rstrm->in_base;
i = (u_int)rstrm->in_boundry % BYTES_PER_XDR_UNIT;
i = (u_long)rstrm->in_boundry % BYTES_PER_XDR_UNIT;
where += i;
len = rstrm->in_size - i;
if ((len = (*(rstrm->readit))(rstrm->tcp_handle, where, len)) == -1)
@ -522,17 +522,17 @@ get_input_bytes(rstrm, addr, len)
register caddr_t addr;
register int len;
{
register int current;
register long current;
while (len > 0) {
current = (int)rstrm->in_boundry - (int)rstrm->in_finger;
current = (long)rstrm->in_boundry - (long)rstrm->in_finger;
if (current == 0) {
if (! fill_input_buf(rstrm))
return (FALSE);
continue;
}
current = (len < current) ? len : current;
bcopy(rstrm->in_finger, addr, current);
memcpy(addr, rstrm->in_finger, current);
rstrm->in_finger += current;
addr += current;
len -= current;
@ -544,7 +544,7 @@ static bool_t /* next two bytes of the input stream are treated as a header */
set_input_fragment(rstrm)
register RECSTREAM *rstrm;
{
u_long header;
u_int32_t header;
if (! get_input_bytes(rstrm, (caddr_t)&header, sizeof(header)))
return (FALSE);
@ -559,10 +559,10 @@ skip_input_bytes(rstrm, cnt)
register RECSTREAM *rstrm;
long cnt;
{
register int current;
register long current;
while (cnt > 0) {
current = (int)rstrm->in_boundry - (int)rstrm->in_finger;
current = (long)rstrm->in_boundry - (long)rstrm->in_finger;
if (current == 0) {
if (! fill_input_buf(rstrm))
return (FALSE);

View File

@ -5,32 +5,32 @@
* may copy or modify Sun RPC without charge, but are not authorized
* to license or distribute it to anyone else except as part of a product or
* program developed by the user.
*
*
* SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
* WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
* PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
*
*
* Sun RPC is provided with no support and without any obligation on the
* part of Sun Microsystems, Inc. to assist in its use, correction,
* modification or enhancement.
*
*
* SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
* INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
* OR ANY PART THEREOF.
*
*
* In no event will Sun Microsystems, Inc. be liable for any lost revenue
* or profits or other special, indirect and consequential damages, even if
* Sun has been advised of the possibility of such damages.
*
*
* Sun Microsystems, Inc.
* 2550 Garcia Avenue
* Mountain View, California 94043
*/
#if defined(LIBC_SCCS) && !defined(lint)
#if defined(LIBC_SCCS) && !defined(lint)
/*static char *sccsid = "from: @(#)xdr_reference.c 1.11 87/08/11 SMI";*/
/*static char *sccsid = "from: @(#)xdr_reference.c 2.1 88/07/29 4.0 RPCSRC";*/
static char *rcsid = "$Id: xdr_reference.c,v 1.1 1993/10/27 05:41:13 paul Exp $";
static char *rcsid = "$Id: xdr_reference.c,v 1.4 1996/12/30 14:07:11 peter Exp $";
#endif
/*
@ -43,10 +43,12 @@ static char *rcsid = "$Id: xdr_reference.c,v 1.1 1993/10/27 05:41:13 paul Exp $"
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <rpc/types.h>
#include <rpc/xdr.h>
#define LASTUNSIGNED ((u_int)0-1)
#define LASTUNSIGNED ((u_int) 0-1)
/*
* XDR an indirect pointer
@ -79,7 +81,7 @@ xdr_reference(xdrs, pp, size, proc)
"xdr_reference: out of memory\n");
return (FALSE);
}
bzero(loc, (int)size);
memset(loc, 0, (int)size);
break;
}

163
lib/libc/xdr/xdr_sizeof.c Normal file
View File

@ -0,0 +1,163 @@
/*
* Sun RPC is a product of Sun Microsystems, Inc. and is provided for
* unrestricted use provided that this legend is included on all tape
* media and as a part of the software program in whole or part. Users
* may copy or modify Sun RPC without charge, but are not authorized
* to license or distribute it to anyone else except as part of a product or
* program developed by the user.
*
* SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
* WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
* PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
*
* Sun RPC is provided with no support and without any obligation on the
* part of Sun Microsystems, Inc. to assist in its use, correction,
* modification or enhancement.
*
* SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
* INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
* OR ANY PART THEREOF.
*
* In no event will Sun Microsystems, Inc. be liable for any lost revenue
* or profits or other special, indirect and consequential damages, even if
* Sun has been advised of the possibility of such damages.
*
* Sun Microsystems, Inc.
* 2550 Garcia Avenue
* Mountain View, California 94043
*/
/*
* xdr_sizeof.c
*
* Copyright 1990 Sun Microsystems, Inc.
*
* General purpose routine to see how much space something will use
* when serialized using XDR.
*/
#include <rpc/types.h>
#include <rpc/xdr.h>
#include <sys/types.h>
#include <stdlib.h>
/* ARGSUSED */
static bool_t
x_putlong(xdrs, longp)
XDR *xdrs;
long *longp;
{
xdrs->x_handy += BYTES_PER_XDR_UNIT;
return (TRUE);
}
/* ARGSUSED */
static bool_t
x_putbytes(xdrs, bp, len)
XDR *xdrs;
char *bp;
int len;
{
xdrs->x_handy += len;
return (TRUE);
}
static u_int
x_getpostn(xdrs)
XDR *xdrs;
{
return (xdrs->x_handy);
}
/* ARGSUSED */
static bool_t
x_setpostn(xdrs, pos)
XDR *xdrs;
u_int pos;
{
/* This is not allowed */
return (FALSE);
}
static int32_t *
x_inline(xdrs, len)
XDR *xdrs;
int len;
{
if (len == 0) {
return (NULL);
}
if (xdrs->x_op != XDR_ENCODE) {
return (NULL);
}
if (len < (int) xdrs->x_base) {
/* x_private was already allocated */
xdrs->x_handy += len;
return ((int32_t *) xdrs->x_private);
} else {
/* Free the earlier space and allocate new area */
if (xdrs->x_private)
free(xdrs->x_private);
if ((xdrs->x_private = (caddr_t) malloc(len)) == NULL) {
xdrs->x_base = 0;
return (NULL);
}
xdrs->x_base = (caddr_t) len;
xdrs->x_handy += len;
return ((int32_t *) xdrs->x_private);
}
}
static int
harmless()
{
/* Always return FALSE/NULL, as the case may be */
return (0);
}
static void
x_destroy(xdrs)
XDR *xdrs;
{
xdrs->x_handy = 0;
xdrs->x_base = 0;
if (xdrs->x_private) {
free(xdrs->x_private);
xdrs->x_private = NULL;
}
return;
}
unsigned long
xdr_sizeof(func, data)
xdrproc_t func;
void *data;
{
XDR x;
struct xdr_ops ops;
bool_t stat;
/* to stop ANSI-C compiler from complaining */
typedef bool_t (* dummyfunc1)(XDR *, long *);
typedef bool_t (* dummyfunc2)(XDR *, caddr_t, u_int);
ops.x_putlong = x_putlong;
ops.x_putbytes = x_putbytes;
ops.x_inline = x_inline;
ops.x_getpostn = x_getpostn;
ops.x_setpostn = x_setpostn;
ops.x_destroy = x_destroy;
/* the other harmless ones */
ops.x_getlong = (dummyfunc1) harmless;
ops.x_getbytes = (dummyfunc2) harmless;
x.x_op = XDR_ENCODE;
x.x_ops = &ops;
x.x_handy = 0;
x.x_private = (caddr_t) NULL;
x.x_base = (caddr_t) 0;
stat = func(&x, data);
if (x.x_private)
free(x.x_private);
return (stat == TRUE ? (unsigned) x.x_handy: 0);
}

View File

@ -5,23 +5,23 @@
* may copy or modify Sun RPC without charge, but are not authorized
* to license or distribute it to anyone else except as part of a product or
* program developed by the user.
*
*
* SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
* WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
* PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
*
*
* Sun RPC is provided with no support and without any obligation on the
* part of Sun Microsystems, Inc. to assist in its use, correction,
* modification or enhancement.
*
*
* SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
* INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
* OR ANY PART THEREOF.
*
*
* In no event will Sun Microsystems, Inc. be liable for any lost revenue
* or profits or other special, indirect and consequential damages, even if
* Sun has been advised of the possibility of such damages.
*
*
* Sun Microsystems, Inc.
* 2550 Garcia Avenue
* Mountain View, California 94043
@ -30,7 +30,7 @@
#if defined(LIBC_SCCS) && !defined(lint)
/*static char *sccsid = "from: @(#)xdr_stdio.c 1.16 87/08/11 Copyr 1984 Sun Micro";*/
/*static char *sccsid = "from: @(#)xdr_stdio.c 2.1 88/07/29 4.0 RPCSRC";*/
static char *rcsid = "$Id: xdr_stdio.c,v 1.1 1993/10/27 05:41:14 paul Exp $";
static char *rcsid = "$Id: xdr_stdio.c,v 1.3 1996/12/30 14:07:11 peter Exp $";
#endif
/*
@ -53,7 +53,7 @@ static bool_t xdrstdio_getbytes();
static bool_t xdrstdio_putbytes();
static u_int xdrstdio_getpos();
static bool_t xdrstdio_setpos();
static long * xdrstdio_inline();
static int32_t *xdrstdio_inline();
static void xdrstdio_destroy();
/*
@ -99,7 +99,7 @@ xdrstdio_destroy(xdrs)
{
(void)fflush((FILE *)xdrs->x_private);
/* xx should we close the file ?? */
};
}
static bool_t
xdrstdio_getlong(xdrs, lp)
@ -107,11 +107,10 @@ xdrstdio_getlong(xdrs, lp)
register long *lp;
{
if (fread((caddr_t)lp, sizeof(long), 1, (FILE *)xdrs->x_private) != 1)
if (fread((caddr_t)lp, sizeof(int32_t), 1,
(FILE *)xdrs->x_private) != 1)
return (FALSE);
#ifndef mc68000
*lp = ntohl(*lp);
#endif
*lp = (long)ntohl((int32_t)*lp);
return (TRUE);
}
@ -121,11 +120,10 @@ xdrstdio_putlong(xdrs, lp)
long *lp;
{
#ifndef mc68000
long mycopy = htonl(*lp);
lp = &mycopy;
#endif
if (fwrite((caddr_t)lp, sizeof(long), 1, (FILE *)xdrs->x_private) != 1)
long mycopy = (long)htonl((int32_t)*lp);
if (fwrite((caddr_t)&mycopy, sizeof(int32_t), 1,
(FILE *)xdrs->x_private) != 1)
return (FALSE);
return (TRUE);
}
@ -163,16 +161,16 @@ xdrstdio_getpos(xdrs)
}
static bool_t
xdrstdio_setpos(xdrs, pos)
xdrstdio_setpos(xdrs, pos)
XDR *xdrs;
u_int pos;
{
{
return ((fseek((FILE *)xdrs->x_private, (long)pos, 0) < 0) ?
FALSE : TRUE);
}
static long *
static int32_t *
xdrstdio_inline(xdrs, len)
XDR *xdrs;
u_int len;