- Missing prototypes, including pointers to functions

- 64 bit long type safe (wire protocols specified in explicit sized types)
- Support systems that don't do unaligned accesses
- Support for explicit int16 and int32 sizes in xdr

Obtained from: a diff of FreeBSD vs. OpenBSD/NetBSD rpc code.
This commit is contained in:
Peter Wemm 1996-12-30 14:07:11 +00:00
parent 889f6ffb91
commit 1ad08a09e9
7 changed files with 375 additions and 150 deletions

View File

@ -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.2 1995/05/30 05:42:03 rgrimes Exp $";
static char *rcsid = "$Id: xdr.c,v 1.3 1995/10/22 14:53:51 phk Exp $";
#endif
/*
@ -45,6 +45,7 @@ static char *rcsid = "$Id: xdr.c,v 1.2 1995/05/30 05:42:03 rgrimes Exp $";
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <rpc/types.h>
#include <rpc/xdr.h>
@ -88,6 +89,7 @@ xdr_void(/* xdrs, addr */)
return (TRUE);
}
/*
* XDR integers
*/
@ -96,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);
}
/*
@ -117,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!
@ -139,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);
}
@ -161,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
*/
@ -214,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:
@ -254,7 +394,7 @@ xdr_char(xdrs, cp)
bool_t
xdr_u_char(xdrs, cp)
XDR *xdrs;
char *cp;
u_char *cp;
{
u_int u;
@ -311,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 {
@ -318,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
}
@ -355,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) {
@ -572,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

@ -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.2 1995/05/30 05:42:04 rgrimes Exp $";
static char *rcsid = "$Id: xdr_array.c,v 1.3 1995/10/22 14:53:54 phk Exp $";
#endif
/*
@ -48,8 +48,7 @@ static char *rcsid = "$Id: xdr_array.c,v 1.2 1995/05/30 05:42:04 rgrimes Exp $";
#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
@ -98,7 +97,7 @@ xdr_array(xdrs, addrp, sizep, maxsize, elsize, elproc)
"xdr_array: out of memory\n");
return (FALSE);
}
bzero(target, nodesize);
memset(target, 0, nodesize);
break;
case XDR_FREE:

View File

@ -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 1994/08/07 18:39:32 wollman Exp $";
static char *rcsid = "$Id: xdr_float.c,v 1.2 1995/05/30 05:42:04 rgrimes Exp $";
#endif
/*
@ -51,10 +51,13 @@ static char *rcsid = "$Id: xdr_float.c,v 1.1 1994/08/07 18:39:32 wollman 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;
@ -104,7 +110,8 @@ xdr_float(xdrs, fp)
case XDR_ENCODE:
#ifdef IEEEFP
return (XDR_PUTLONG(xdrs, (long *)fp));
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

@ -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.2 1995/05/30 05:42:06 rgrimes Exp $";
static char *rcsid = "$Id: xdr_mem.c,v 1.3 1995/10/22 14:53:55 phk Exp $";
#endif
/*
@ -49,23 +49,37 @@ static char *rcsid = "$Id: xdr_mem.c,v 1.2 1995/05/30 05:42:06 rgrimes Exp $";
#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
};
@ -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

@ -29,7 +29,7 @@
#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.3 1995/05/30 05:42:09 rgrimes Exp $";
static char *rcsid = "$Id: xdr_rec.c,v 1.4 1995/10/22 14:53:56 phk Exp $";
#endif
/*
@ -68,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 = {
@ -95,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;
@ -103,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 */
@ -164,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;
/*
@ -176,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;
@ -199,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);
}
@ -222,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);
}
@ -275,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;
@ -300,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) {
@ -313,7 +314,7 @@ xdrrec_getpos(xdrs)
break;
default:
pos = (u_int) -1;
pos = -1;
break;
}
return ((u_int) pos);
@ -355,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;
@ -375,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;
}
@ -459,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);
}
@ -482,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);
}
@ -500,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)
@ -521,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;
@ -543,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);
@ -558,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

@ -30,7 +30,7 @@
#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.2 1995/05/30 05:42:12 rgrimes Exp $";
static char *rcsid = "$Id: xdr_reference.c,v 1.3 1995/10/22 14:53:58 phk Exp $";
#endif
/*
@ -48,7 +48,7 @@ static char *rcsid = "$Id: xdr_reference.c,v 1.2 1995/05/30 05:42:12 rgrimes Exp
#include <rpc/types.h>
#include <rpc/xdr.h>
#define LASTUNSIGNED ((u_int)0-1)
#define LASTUNSIGNED ((u_int) 0-1)
/*
* XDR an indirect pointer
@ -81,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;
}

View File

@ -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 1994/08/07 18:39:35 wollman Exp $";
static char *rcsid = "$Id: xdr_stdio.c,v 1.2 1995/05/30 05:42:12 rgrimes 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);
}
@ -172,7 +170,7 @@ xdrstdio_setpos(xdrs, pos)
FALSE : TRUE);
}
static long *
static int32_t *
xdrstdio_inline(xdrs, len)
XDR *xdrs;
u_int len;