1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
|
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2015 Gary Mills
*/
/*
* This is a non-recursive version of XDR routine used for db_index_entry
* type.
*/
#include <sys/types.h>
#include <sys/syslog.h>
#include <stdio.h>
#include <rpc/types.h>
#include <rpc/xdr.h>
#include <memory.h>
#include "db_index_entry_c.h"
#include "db_table_c.h"
#include "xdr_nullptr.h"
bool_t
xdr_db_index_entry(xdrs, objp)
register XDR *xdrs;
db_index_entry *objp;
{
bool_t more_data;
register db_index_entry *ep = objp;
register db_index_entry *loc;
register db_index_entry *freeptr = NULL;
for (;;) {
if (!xdr_u_long(xdrs, &ep->hashval))
return (FALSE);
if (!xdr_pointer(xdrs, (char **)&ep->key, sizeof (item),
(xdrproc_t) xdr_item))
return (FALSE);
if (!xdr_entryp(xdrs, &ep->location))
return (FALSE);
if (!xdr_nullptr(xdrs, &ep->next_result))
return (FALSE);
/*
* The following code replaces the call to
* xdr_pointer(
* xdrs,
* (char **)&ep->next,
* sizeof (db_index_entry),
* (xdrproc_t) xdr_db_index_entry))
*
* It's a modified version of xdr_refer.c from the rpc library:
* @(#)xdr_refer.c 1.8 92/07/20 SMI
*/
/*
* the following assignment to more_data is only useful when
* encoding and freeing. When decoding, more_data will be
* filled by the xdr_bool() routine.
*/
more_data = (ep->next != NULL);
if (! xdr_bool(xdrs, &more_data))
return (FALSE);
if (! more_data) {
ep->next = NULL;
break;
}
loc = ep->next;
switch (xdrs->x_op) {
case XDR_DECODE:
if (loc == NULL) {
ep->next = loc = (db_index_entry *)
mem_alloc(sizeof (db_index_entry));
if (loc == NULL) {
syslog(LOG_ERR,
"xdr_db_index_entry: mem_alloc failed");
return (FALSE);
}
memset(loc, 0, sizeof (db_index_entry));
}
break;
case XDR_FREE:
if (freeptr != NULL) {
mem_free(freeptr, sizeof (db_index_entry));
} else
ep->next = NULL;
freeptr = loc;
break;
}
if (loc == NULL)
break;
ep = loc;
} /* for loop */
if ((freeptr != NULL) && (xdrs->x_op == XDR_FREE)) {
mem_free(freeptr, sizeof (db_index_entry));
}
return (TRUE);
}
bool_t
xdr_db_index_entry_p(xdrs, objp)
register XDR *xdrs;
db_index_entry_p *objp;
{
if (!xdr_pointer(xdrs, (char **)objp, sizeof (db_index_entry),
(xdrproc_t) xdr_db_index_entry))
return (FALSE);
return (TRUE);
}
bool_t
xdr_db_free_entry(xdrs, objp)
register XDR *xdrs;
db_free_entry *objp;
{
bool_t more_data;
register db_free_entry *ep = objp;
register db_free_entry *loc;
register db_free_entry *freeptr = NULL;
for (;;) {
if (!xdr_entryp(xdrs, &ep->where))
return (FALSE);
/*
* The following code replaces the call to
* xdr_pointer(
* xdrs,
* (char **)&ep->next,
* sizeof (db_free_entry),
* (xdrproc_t) xdr_db_free_entry))
*
* It's a modified version of xdr_refer.c from the rpc library:
* @(#)xdr_refer.c 1.8 92/07/20 SMI
*/
/*
* the following assignment to more_data is only useful when
* encoding and freeing. When decoding, more_data will be
* filled by the xdr_bool() routine.
*/
more_data = (ep->next != NULL);
if (! xdr_bool(xdrs, &more_data))
return (FALSE);
if (! more_data) {
ep->next = NULL;
break;
}
loc = ep->next;
switch (xdrs->x_op) {
case XDR_DECODE:
if (loc == NULL) {
ep->next = loc = (db_free_entry *)
mem_alloc(sizeof (db_free_entry));
if (loc == NULL) {
syslog(LOG_ERR,
"db_free_entry: mem_alloc failed");
return (FALSE);
}
memset(loc, 0, sizeof (db_free_entry));
}
break;
case XDR_FREE:
if (freeptr != NULL) {
mem_free(freeptr, sizeof (db_free_entry));
} else
ep->next = NULL;
freeptr = loc;
break;
}
if (loc == NULL)
break;
ep = loc;
} /* for loop */
if ((freeptr != NULL) && (xdrs->x_op == XDR_FREE)) {
mem_free(freeptr, sizeof (db_free_entry));
}
return (TRUE);
}
|