summaryrefslogtreecommitdiff
path: root/libc/inet/rpc
diff options
context:
space:
mode:
Diffstat (limited to 'libc/inet/rpc')
-rw-r--r--libc/inet/rpc/create_xid.c3
-rw-r--r--libc/inet/rpc/xdr.c20
-rw-r--r--libc/inet/rpc/xdr_intXX_t.c4
-rw-r--r--libc/inet/rpc/xdr_rec.c103
4 files changed, 54 insertions, 76 deletions
diff --git a/libc/inet/rpc/create_xid.c b/libc/inet/rpc/create_xid.c
index be24d660c..0f045b9c1 100644
--- a/libc/inet/rpc/create_xid.c
+++ b/libc/inet/rpc/create_xid.c
@@ -34,14 +34,13 @@
#include <bits/uClibc_mutex.h>
__UCLIBC_MUTEX_STATIC(mylock, PTHREAD_MUTEX_INITIALIZER);
-
static smallint is_initialized;
static struct drand48_data __rpc_lrand48_data;
u_long _create_xid (void) attribute_hidden;
u_long _create_xid (void)
{
- unsigned long res;
+ long res;
__UCLIBC_MUTEX_LOCK(mylock);
diff --git a/libc/inet/rpc/xdr.c b/libc/inet/rpc/xdr.c
index 11e52136d..f76cc6a88 100644
--- a/libc/inet/rpc/xdr.c
+++ b/libc/inet/rpc/xdr.c
@@ -104,7 +104,6 @@ libc_hidden_def(xdr_void)
bool_t
xdr_long (XDR *xdrs, long *lp)
{
-
if (xdrs->x_op == XDR_ENCODE
&& (sizeof (int32_t) == sizeof (long)
|| (int32_t) *lp == *lp))
@@ -237,10 +236,10 @@ xdr_u_int (XDR *xdrs, u_int *up)
{
case XDR_ENCODE:
l = (u_long) * up;
- return XDR_PUTLONG (xdrs, &l);
+ return XDR_PUTLONG (xdrs, (long *) &l);
case XDR_DECODE:
- if (!XDR_GETLONG (xdrs, &l))
+ if (!XDR_GETLONG (xdrs, (long *) &l))
{
return FALSE;
}
@@ -268,19 +267,20 @@ bool_t
xdr_hyper (XDR *xdrs, quad_t *llp)
{
long t1;
- unsigned long int t2;
+ unsigned long t2;
if (xdrs->x_op == XDR_ENCODE)
{
t1 = (long) ((*llp) >> 32);
t2 = (long) (*llp);
- return (XDR_PUTLONG(xdrs, &t1) && XDR_PUTLONG(xdrs, &t2));
+ return (XDR_PUTLONG(xdrs, &t1) && XDR_PUTLONG(xdrs, (long *) &t2));
}
if (xdrs->x_op == XDR_DECODE)
{
- if (!XDR_GETLONG(xdrs, &t1) || !XDR_GETLONG(xdrs, &t2))
+ if (!XDR_GETLONG(xdrs, &t1) || !XDR_GETLONG(xdrs, (long *) &t2))
return FALSE;
+ /* t2 must be unsigned for this to work */
*llp = ((quad_t) t1) << 32;
*llp |= t2;
return TRUE;
@@ -309,12 +309,12 @@ xdr_u_hyper (XDR *xdrs, u_quad_t *ullp)
{
t1 = (unsigned long) ((*ullp) >> 32);
t2 = (unsigned long) (*ullp);
- return (XDR_PUTLONG(xdrs, &t1) && XDR_PUTLONG(xdrs, &t2));
+ return (XDR_PUTLONG(xdrs, (long *) &t1) && XDR_PUTLONG(xdrs, (long *) &t2));
}
if (xdrs->x_op == XDR_DECODE)
{
- if (!XDR_GETLONG(xdrs, &t1) || !XDR_GETLONG(xdrs, &t2))
+ if (!XDR_GETLONG(xdrs, (long *) &t1) || !XDR_GETLONG(xdrs, (long *) &t2))
return FALSE;
*ullp = ((u_quad_t) t1) << 32;
*ullp |= t2;
@@ -353,10 +353,10 @@ xdr_u_short (XDR *xdrs, u_short *usp)
{
case XDR_ENCODE:
l = (u_long) * usp;
- return XDR_PUTLONG (xdrs, &l);
+ return XDR_PUTLONG (xdrs, (long *) &l);
case XDR_DECODE:
- if (!XDR_GETLONG (xdrs, &l))
+ if (!XDR_GETLONG (xdrs, (long *) &l))
{
return FALSE;
}
diff --git a/libc/inet/rpc/xdr_intXX_t.c b/libc/inet/rpc/xdr_intXX_t.c
index d36d1623b..ff2177584 100644
--- a/libc/inet/rpc/xdr_intXX_t.c
+++ b/libc/inet/rpc/xdr_intXX_t.c
@@ -34,9 +34,9 @@ xdr_int64_t (XDR *xdrs, int64_t *ip)
case XDR_ENCODE:
t1 = (int32_t) ((*ip) >> 32);
t2 = (int32_t) (*ip);
- return (XDR_PUTINT32(xdrs, &t1) && XDR_PUTINT32(xdrs, &t2));
+ return (XDR_PUTINT32(xdrs, &t1) && XDR_PUTINT32(xdrs, (int32_t *) &t2));
case XDR_DECODE:
- if (!XDR_GETINT32(xdrs, &t1) || !XDR_GETINT32(xdrs, &t2))
+ if (!XDR_GETINT32(xdrs, &t1) || !XDR_GETINT32(xdrs, (int32_t *) &t2))
return FALSE;
*ip = ((int64_t) t1) << 32;
*ip |= t2;
diff --git a/libc/inet/rpc/xdr_rec.c b/libc/inet/rpc/xdr_rec.c
index af5eb5217..43dff2206 100644
--- a/libc/inet/rpc/xdr_rec.c
+++ b/libc/inet/rpc/xdr_rec.c
@@ -64,20 +64,27 @@
/* libc_hidden_proto(fputs) */
/* libc_hidden_proto(lseek) */
-static bool_t xdrrec_getlong (XDR *, long *);
-static bool_t xdrrec_putlong (XDR *, const long *);
static bool_t xdrrec_getbytes (XDR *, caddr_t, u_int);
static bool_t xdrrec_putbytes (XDR *, const char *, u_int);
+static bool_t xdrrec_getint32 (XDR *, int32_t *);
+static bool_t xdrrec_putint32 (XDR *, const int32_t *);
+#if ULONG_MAX != UINT_MAX
+static bool_t xdrrec_getlong (XDR *, long *);
+static bool_t xdrrec_putlong (XDR *, const long *);
+#endif
static u_int xdrrec_getpos (const XDR *);
static bool_t xdrrec_setpos (XDR *, u_int);
static int32_t *xdrrec_inline (XDR *, u_int);
static void xdrrec_destroy (XDR *);
-static bool_t xdrrec_getint32 (XDR *, int32_t *);
-static bool_t xdrrec_putint32 (XDR *, const int32_t *);
static const struct xdr_ops xdrrec_ops = {
+#if ULONG_MAX == UINT_MAX
+ (bool_t (*)(XDR *, long *)) xdrrec_getint32,
+ (bool_t (*)(XDR *, const long *)) xdrrec_putint32,
+#else
xdrrec_getlong,
xdrrec_putlong,
+#endif
xdrrec_getbytes,
xdrrec_putbytes,
xdrrec_getpos,
@@ -218,35 +225,46 @@ libc_hidden_def(xdrrec_create)
*/
static bool_t
-xdrrec_getlong (XDR *xdrs, long *lp)
+xdrrec_getint32 (XDR *xdrs, int32_t *ip)
{
RECSTREAM *rstrm = (RECSTREAM *) xdrs->x_private;
- int32_t *buflp = (int32_t *) rstrm->in_finger;
+ int32_t *bufip = (int32_t *) rstrm->in_finger;
int32_t mylong;
/* first try the inline, fast case */
if (rstrm->fbtbc >= BYTES_PER_XDR_UNIT &&
- rstrm->in_boundry - (char *) buflp >= BYTES_PER_XDR_UNIT)
+ rstrm->in_boundry - (char *) bufip >= BYTES_PER_XDR_UNIT)
{
- *lp = (int32_t) ntohl (*buflp);
+ *ip = ntohl (*bufip);
rstrm->fbtbc -= BYTES_PER_XDR_UNIT;
rstrm->in_finger += BYTES_PER_XDR_UNIT;
}
else
{
- if (!xdrrec_getbytes (xdrs, (caddr_t) & mylong,
+ if (!xdrrec_getbytes (xdrs, (caddr_t) &mylong,
BYTES_PER_XDR_UNIT))
return FALSE;
- *lp = (int32_t) ntohl (mylong);
+ *ip = ntohl (mylong);
}
return TRUE;
}
+#if ULONG_MAX != UINT_MAX
static bool_t
-xdrrec_putlong (XDR *xdrs, const long *lp)
+xdrrec_getlong (XDR *xdrs, long *lp)
+{
+ int32_t v;
+ bool_t r = xdrrec_getint32 (xdrs, &v);
+ *lp = v;
+ return r;
+}
+#endif
+
+static bool_t
+xdrrec_putint32 (XDR *xdrs, const int32_t *ip)
{
RECSTREAM *rstrm = (RECSTREAM *) xdrs->x_private;
- int32_t *dest_lp = (int32_t *) rstrm->out_finger;
+ int32_t *dest_ip = (int32_t *) rstrm->out_finger;
if ((rstrm->out_finger += BYTES_PER_XDR_UNIT) > rstrm->out_boundry)
{
@@ -258,13 +276,22 @@ xdrrec_putlong (XDR *xdrs, const long *lp)
rstrm->frag_sent = TRUE;
if (!flush_out (rstrm, FALSE))
return FALSE;
- dest_lp = (int32_t *) rstrm->out_finger;
+ dest_ip = (int32_t *) rstrm->out_finger;
rstrm->out_finger += BYTES_PER_XDR_UNIT;
}
- *dest_lp = htonl (*lp);
+ *dest_ip = htonl (*ip);
return TRUE;
}
+#if ULONG_MAX != UINT_MAX
+static bool_t
+xdrrec_putlong (XDR *xdrs, const long *lp)
+{
+ int32_t v = *lp;
+ return xdrrec_putint32 (xdrs, &v);
+}
+#endif
+
static bool_t /* must manage buffers, fragments, and records */
xdrrec_getbytes (XDR *xdrs, caddr_t addr, u_int len)
{
@@ -425,54 +452,6 @@ xdrrec_destroy (XDR *xdrs)
mem_free ((caddr_t) rstrm, sizeof (RECSTREAM));
}
-static bool_t
-xdrrec_getint32 (XDR *xdrs, int32_t *ip)
-{
- RECSTREAM *rstrm = (RECSTREAM *) xdrs->x_private;
- int32_t *bufip = (int32_t *) rstrm->in_finger;
- int32_t mylong;
-
- /* first try the inline, fast case */
- if (rstrm->fbtbc >= BYTES_PER_XDR_UNIT &&
- rstrm->in_boundry - (char *) bufip >= BYTES_PER_XDR_UNIT)
- {
- *ip = ntohl (*bufip);
- rstrm->fbtbc -= BYTES_PER_XDR_UNIT;
- rstrm->in_finger += BYTES_PER_XDR_UNIT;
- }
- else
- {
- if (!xdrrec_getbytes (xdrs, (caddr_t) &mylong,
- BYTES_PER_XDR_UNIT))
- return FALSE;
- *ip = ntohl (mylong);
- }
- return TRUE;
-}
-
-static bool_t
-xdrrec_putint32 (XDR *xdrs, const int32_t *ip)
-{
- RECSTREAM *rstrm = (RECSTREAM *) xdrs->x_private;
- int32_t *dest_ip = (int32_t *) rstrm->out_finger;
-
- if ((rstrm->out_finger += BYTES_PER_XDR_UNIT) > rstrm->out_boundry)
- {
- /*
- * this case should almost never happen so the code is
- * inefficient
- */
- rstrm->out_finger -= BYTES_PER_XDR_UNIT;
- rstrm->frag_sent = TRUE;
- if (!flush_out (rstrm, FALSE))
- return FALSE;
- dest_ip = (int32_t *) rstrm->out_finger;
- rstrm->out_finger += BYTES_PER_XDR_UNIT;
- }
- *dest_ip = htonl (*ip);
- return TRUE;
-}
-
/*
* Exported routines to manage xdr records
*/