summaryrefslogtreecommitdiff
path: root/libc/inet/rpc/xdr_rec.c
diff options
context:
space:
mode:
Diffstat (limited to 'libc/inet/rpc/xdr_rec.c')
-rw-r--r--libc/inet/rpc/xdr_rec.c103
1 files changed, 41 insertions, 62 deletions
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
*/