Files
Arquivotheca.AIX-4.1.3/bos/usr/ccs/lib/libc/xdr_reference.c
seta75D d6fe8fe829 Init
2021-10-11 22:19:34 -03:00

143 lines
3.3 KiB
C

static char sccsid[] = "@(#)22 1.1 src/bos/usr/ccs/lib/libc/xdr_reference.c, libcrpc, bos411, 9428A410j 10/25/93 20:54:35";
/*
* COMPONENT_NAME: LIBCRPC
*
* FUNCTIONS: xdr_pointer
* xdr_reference
*
*
* ORIGINS: 24,27
*
* This module contains IBM CONFIDENTIAL code. -- (IBM
* Confidential Restricted when combined with the aggregated
* modules for this product)
* SOURCE MATERIALS
*
* (C) COPYRIGHT International Business Machines Corp. 1989,1993
* All Rights Reserved
* US Government Users Restricted Rights - Use, duplication or
* disclosure restricted by GSA ADP Schedule Contract with IBM Corp.
*/
/*
#if defined(LIBC_SCCS) && !defined(lint)
static char sccsid[] = "@(#)xdr_reference.c 1.5 90/07/19 4.1NFSSRC Copyr 1990 Sun Micro";
#endif
*
* Copyright (c) 1988 by Sun Microsystems, Inc.
* 1.12 88/02/08
*/
/*
* xdr_reference.c, Generic XDR routines impelmentation.
*
* These are the "non-trivial" xdr primitives used to serialize and de-serialize
* "pointers". See xdr.h for more info on the interface to xdr.
*/
#ifdef _KERNEL
#include <sys/param.h>
#include <rpc/types.h>
#include <rpc/xdr.h>
#else
#include <sys/syslog.h>
#include <stdio.h>
#include <rpc/types.h>
#include <rpc/xdr.h>
#include <libc_msg.h>
#endif
#define LASTUNSIGNED ((u_int)0-1)
/*
* XDR an indirect pointer
* xdr_reference is for recursively translating a structure that is
* referenced by a pointer inside the structure that is currently being
* translated. pp references a pointer to storage. If *pp is null
* the necessary storage is allocated.
* size is the sizeof the referneced structure.
* proc is the routine to handle the referenced structure.
*/
bool_t
xdr_reference(xdrs, pp, size, proc)
register XDR *xdrs;
caddr_t *pp; /* the pointer to work on */
u_int size; /* size of the object pointed to */
xdrproc_t proc; /* xdr routine to handle the object */
{
register caddr_t loc = *pp;
register bool_t stat;
if (loc == NULL)
switch (xdrs->x_op) {
case XDR_FREE:
return (TRUE);
case XDR_DECODE:
*pp = loc = (caddr_t) mem_alloc(size);
if (loc == NULL) {
#ifndef _KERNEL
(void) syslog(LOG_ERR,
(char *)oncmsg(LIBCRPC,RPC97,
"xdr_reference: out of memory"));
#endif
return (FALSE);
}
bzero(loc, size);
break;
}
stat = (*proc)(xdrs, loc, LASTUNSIGNED);
if (xdrs->x_op == XDR_FREE) {
mem_free(loc, size);
*pp = NULL;
}
return (stat);
}
#ifndef _KERNEL
/*
* xdr_pointer():
*
* XDR a pointer to a possibly recursive data structure. This
* differs with xdr_reference in that it can serialize/deserialiaze
* trees correctly.
*
* What's sent is actually a union:
*
* union object_pointer switch (boolean b) {
* case TRUE: object_data data;
* case FALSE: void nothing;
* }
*
* > objpp: Pointer to the pointer to the object.
* > obj_size: size of the object.
* > xdr_obj: routine to XDR an object.
*
*/
bool_t
xdr_pointer(xdrs,objpp,obj_size,xdr_obj)
register XDR *xdrs;
char **objpp;
u_int obj_size;
xdrproc_t xdr_obj;
{
bool_t more_data;
more_data = (*objpp != NULL);
if (! xdr_bool(xdrs,&more_data)) {
return (FALSE);
}
if (! more_data) {
*objpp = NULL;
return (TRUE);
}
return (xdr_reference(xdrs,objpp,obj_size,xdr_obj));
}
#endif /* ! _KERNEL */