Back to index

glibc  2.9
Defines | Functions
xdr_array.c File Reference
#include <stdio.h>
#include <string.h>
#include <rpc/types.h>
#include <rpc/xdr.h>
#include <libintl.h>
#include <limits.h>

Go to the source code of this file.

Defines

#define LASTUNSIGNED   ((u_int)0-1)

Functions

bool_t xdr_array (XDR *xdrs, caddr_t *addrp, u_int *sizep, u_int maxsize, u_int elsize, xdrproc_t elproc)
bool_t xdr_vector (XDR *xdrs, char *basep, u_int nelem, u_int elemsize, xdrproc_t xdr_elem)

Define Documentation

#define LASTUNSIGNED   ((u_int)0-1)

Definition at line 54 of file xdr_array.c.


Function Documentation

bool_t xdr_array ( XDR xdrs,
caddr_t addrp,
u_int sizep,
u_int  maxsize,
u_int  elsize,
xdrproc_t  elproc 
)

Definition at line 65 of file xdr_array.c.

{
  u_int i;
  caddr_t target = *addrp;
  u_int c;           /* the actual element count */
  bool_t stat = TRUE;

  /* like strings, arrays are really counted arrays */
  if (!INTUSE(xdr_u_int) (xdrs, sizep))
    {
      return FALSE;
    }
  c = *sizep;
  /*
   * XXX: Let the overflow possibly happen with XDR_FREE because mem_free()
   * doesn't actually use its second argument anyway.
   */
  if ((c > maxsize || c > UINT_MAX / elsize) && (xdrs->x_op != XDR_FREE))
    {
      return FALSE;
    }

  /*
   * if we are deserializing, we may need to allocate an array.
   * We also save time by checking for a null array if we are freeing.
   */
  if (target == NULL)
    switch (xdrs->x_op)
      {
      case XDR_DECODE:
       if (c == 0)
         return TRUE;
       *addrp = target = calloc (c, elsize);
       if (target == NULL)
         {
           (void) __fxprintf (NULL, "%s: %s", __func__, _("out of memory\n"));
           return FALSE;
         }
       break;

      case XDR_FREE:
       return TRUE;
      default:
       break;
      }

  /*
   * now we xdr each element of array
   */
  for (i = 0; (i < c) && stat; i++)
    {
      stat = (*elproc) (xdrs, target, LASTUNSIGNED);
      target += elsize;
    }

  /*
   * the array may need freeing
   */
  if (xdrs->x_op == XDR_FREE)
    {
      mem_free (*addrp, c * elsize);
      *addrp = NULL;
    }
  return stat;
}

Here is the call graph for this function:

Here is the caller graph for this function:

bool_t xdr_vector ( XDR xdrs,
char *  basep,
u_int  nelem,
u_int  elemsize,
xdrproc_t  xdr_elem 
)

Definition at line 149 of file xdr_array.c.

{
  u_int i;
  char *elptr;

  elptr = basep;
  for (i = 0; i < nelem; i++)
    {
      if (!(*xdr_elem) (xdrs, elptr, LASTUNSIGNED))
       {
         return FALSE;
       }
      elptr += elemsize;
    }
  return TRUE;
}