Skip to content

Instantly share code, notes, and snippets.

@Supermathie
Created April 15, 2013 16:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Supermathie/5389349 to your computer and use it in GitHub Desktop.
Save Supermathie/5389349 to your computer and use it in GitHub Desktop.
xdr_opaque glibc source (RHEl6)
/*
* XDR opaque data
* Allows the specification of a fixed size sequence of opaque bytes.
* cp points to the opaque object and cnt gives the byte length.
*/
bool_t
xdr_opaque (XDR *xdrs, caddr_t cp, u_int cnt)
{
u_int rndup;
static char crud[BYTES_PER_XDR_UNIT];
/*
* if no data we are done
*/
if (cnt == 0)
return TRUE;
/*
* round byte count to full xdr units
*/
rndup = cnt % BYTES_PER_XDR_UNIT;
if (rndup > 0)
rndup = BYTES_PER_XDR_UNIT - rndup;
switch (xdrs->x_op)
{
case XDR_DECODE:
if (!XDR_GETBYTES (xdrs, cp, cnt))
{
return FALSE;
}
if (rndup == 0)
return TRUE;
return XDR_GETBYTES (xdrs, (caddr_t)crud, rndup);
case XDR_ENCODE:
if (!XDR_PUTBYTES (xdrs, cp, cnt))
{
return FALSE;
}
if (rndup == 0)
return TRUE;
return XDR_PUTBYTES (xdrs, xdr_zero, rndup);
case XDR_FREE:
return TRUE;
}
return FALSE;
}
INTDEF(xdr_opaque)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment