Cleaner fix part 1
[bluesky.git] / TBBT / trace_play / rpc / pmap_prot2.c
1 #ifndef lint
2 static char sfs_clnt_id[] = "@(#)pmap_prot2.c     2.1     97/10/23";
3 #endif
4 /* @(#)pmap_prot2.c     2.1 88/07/29 4.0 RPCSRC */
5 /*
6  *   Copyright (c) 1992-1997,2001 by Standard Performance Evaluation Corporation
7  *      All rights reserved.
8  *              Standard Performance Evaluation Corporation (SPEC)
9  *              6585 Merchant Place, Suite 100
10  *              Warrenton, VA 20187
11  *
12  *      This product contains benchmarks acquired from several sources who
13  *      understand and agree with SPEC's goal of creating fair and objective
14  *      benchmarks to measure computer performance.
15  *
16  *      This copyright notice is placed here only to protect SPEC in the
17  *      event the source is misused in any manner that is contrary to the
18  *      spirit, the goals and the intent of SPEC.
19  *
20  *      The source code is provided to the user or company under the license
21  *      agreement for the SPEC Benchmark Suite for this product.
22  */
23 /*
24  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
25  * unrestricted use provided that this legend is included on all tape
26  * media and as a part of the software program in whole or part.  Users
27  * may copy or modify Sun RPC without charge, but are not authorized
28  * to license or distribute it to anyone else except as part of a product or
29  * program developed by the user.
30  * 
31  * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
32  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
33  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
34  * 
35  * Sun RPC is provided with no support and without any obligation on the
36  * part of Sun Microsystems, Inc. to assist in its use, correction,
37  * modification or enhancement.
38  * 
39  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
40  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
41  * OR ANY PART THEREOF.
42  * 
43  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
44  * or profits or other special, indirect and consequential damages, even if
45  * Sun has been advised of the possibility of such damages.
46  * 
47  * Sun Microsystems, Inc.
48  * 2550 Garcia Avenue
49  * Mountain View, California  94043
50  */
51 #if !defined(lint) && defined(SCCSIDS)
52 static char sccsid[] = "@(#)pmap_prot2.c 1.3 87/08/11 Copyr 1984 Sun Micro";
53 #endif
54
55 /*
56  * pmap_prot2.c
57  * Protocol for the local binder service, or pmap.
58  *
59  * Copyright (C) 1984, Sun Microsystems, Inc.
60  */
61
62 #include "rpc/types.h"
63 #include "rpc/xdr.h"
64 #include "rpc/pmap_prot.h"
65
66
67 /* 
68  * What is going on with linked lists? (!)
69  * First recall the link list declaration from pmap_prot.h:
70  *
71  * struct pmaplist {
72  *      struct pmap pml_map;
73  *      struct pmaplist *pml_map;
74  * };
75  *
76  * Compare that declaration with a corresponding xdr declaration that 
77  * is (a) pointer-less, and (b) recursive:
78  *
79  * typedef union switch (bool_t) {
80  * 
81  *      case TRUE: struct {
82  *              struct pmap;
83  *              pmaplist_t foo;
84  *      };
85  *
86  *      case FALSE: struct {};
87  * } pmaplist_t;
88  *
89  * Notice that the xdr declaration has no nxt pointer while
90  * the C declaration has no bool_t variable.  The bool_t can be
91  * interpreted as ``more data follows me''; if FALSE then nothing
92  * follows this bool_t; if TRUE then the bool_t is followed by
93  * an actual struct pmap, and then (recursively) by the 
94  * xdr union, pamplist_t.  
95  *
96  * This could be implemented via the xdr_union primitive, though this
97  * would cause a one recursive call per element in the list.  Rather than do
98  * that we can ``unwind'' the recursion
99  * into a while loop and do the union arms in-place.
100  *
101  * The head of the list is what the C programmer wishes to past around
102  * the net, yet is the data that the pointer points to which is interesting;
103  * this sounds like a job for xdr_reference!
104  */
105 bool_t
106 xdr_pmaplist(
107         XDR *xdrs,
108         struct pmaplist **rp)
109 {
110         /*
111          * more_elements is pre-computed in case the direction is
112          * XDR_ENCODE or XDR_FREE.  more_elements is overwritten by
113          * xdr_bool when the direction is XDR_DECODE.
114          */
115         bool_t more_elements;
116         register int freeing = (xdrs->x_op == XDR_FREE);
117         register struct pmaplist **next;
118
119         /* CONSTCOND */
120         while (TRUE) {
121                 more_elements = (bool_t)(*rp != NULL);
122                 if (! xdr_bool(xdrs, &more_elements))
123                         return (FALSE);
124                 if (! more_elements)
125                         return (TRUE);  /* we are done */
126                 /*
127                  * the unfortunate side effect of non-recursion is that in
128                  * the case of freeing we must remember the next object
129                  * before we free the current object ...
130                  */
131                 if (freeing)
132                         next = &((*rp)->pml_next); 
133                 if (! xdr_reference(xdrs, (void **)rp,
134                     (uint_t)sizeof(struct pmaplist), xdr_pmap))
135                         return (FALSE);
136                 rp = (freeing) ? next : &((*rp)->pml_next);
137         }
138 }