/*
* xdr.c, Generic XDR routines implementation.
*
* Copyright (c) 2010, Oracle America, Inc.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are
* met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials
* provided with the distribution.
* * Neither the name of the "Oracle America, Inc." nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* These are the "generic" xdr routines used to serialize and de-serialize
* most common data items. See xdr.h for more info on the interface to
* xdr.
*/
#include <stdio.h>
#include <limits.h>
#include <string.h>
#include <libintl.h>
#include <wchar.h>
#include <stdint.h>
#include <rpc/types.h>
#include <rpc/xdr.h>
#include <shlib-compat.h>
/*
* constants specific to the xdr "protocol"
*/
#define XDR_FALSE ((long) 0)
#define XDR_TRUE ((long) 1)
#define LASTUNSIGNED ((u_int) 0-1)
/*
* for unit alignment
*/
static const char xdr_zero[BYTES_PER_XDR_UNIT] = {0, 0, 0, 0};
/*
* Free a data structure using XDR
* Not a filter, but a convenient utility nonetheless
*/
void
xdr_free (xdrproc_t proc, char *objp)
{
XDR x;
x.x_op = XDR_FREE;
(*proc) (&x, objp);
}
#ifdef EXPORT_RPC_SYMBOLS
libc_hidden_def (xdr_free)
#else
libc_hidden_nolink_sunrpc (xdr_free, GLIBC_2_0)
#endif
/*
* XDR nothing
*/
bool_t
xdr_void (void)
{
return TRUE;
}
#ifdef EXPORT_RPC_SYMBOLS
libc_hidden_def (xdr_void)
#else
libc_hidden_nolink_sunrpc (xdr_void, GLIBC_2_0)
#endif
/*
* XDR integers
*/
bool_t
xdr_int (XDR *xdrs, int *ip)
{
#if INT_MAX < LONG_MAX
long l;
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;
}