1 /* Copyright (c) 1998, 1999, 2000 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1998.
4
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
18
19 #include <rpc/types.h>
20 #include <rpc/xdr.h>
21
22 /* XDR 64bit integers */
23 bool_t
xdr_int64_t(XDR * xdrs,int64_t * ip)24 xdr_int64_t (XDR *xdrs, int64_t *ip)
25 {
26 int32_t t1;
27 /* This must be unsigned, otherwise we get problems with sign
28 extension in the DECODE case. */
29 uint32_t t2;
30
31 switch (xdrs->x_op)
32 {
33 case XDR_ENCODE:
34 t1 = (int32_t) ((*ip) >> 32);
35 t2 = (int32_t) (*ip);
36 return (XDR_PUTINT32(xdrs, &t1) && XDR_PUTINT32(xdrs, (int32_t *) &t2));
37 case XDR_DECODE:
38 if (!XDR_GETINT32(xdrs, &t1) || !XDR_GETINT32(xdrs, (int32_t *) &t2))
39 return FALSE;
40 *ip = ((int64_t) t1) << 32;
41 *ip |= t2;
42 return TRUE;
43 case XDR_FREE:
44 return TRUE;
45 default:
46 return FALSE;
47 }
48 }
strong_alias_untyped(xdr_int64_t,xdr_quad_t)49 strong_alias_untyped(xdr_int64_t,xdr_quad_t)
50
51 /* XDR 64bit unsigned integers */
52 bool_t
53 xdr_uint64_t (XDR *xdrs, uint64_t *uip)
54 {
55 uint32_t t1;
56 uint32_t t2;
57
58 switch (xdrs->x_op)
59 {
60 case XDR_ENCODE:
61 t1 = (uint32_t) ((*uip) >> 32);
62 t2 = (uint32_t) (*uip);
63 return (XDR_PUTINT32 (xdrs, (int32_t *) &t1) &&
64 XDR_PUTINT32(xdrs, (int32_t *) &t2));
65 case XDR_DECODE:
66 if (!XDR_GETINT32(xdrs, (int32_t *) &t1) ||
67 !XDR_GETINT32(xdrs, (int32_t *) &t2))
68 return FALSE;
69 *uip = ((uint64_t) t1) << 32;
70 *uip |= t2;
71 return TRUE;
72 case XDR_FREE:
73 return TRUE;
74 default:
75 return FALSE;
76 }
77 }
strong_alias_untyped(xdr_uint64_t,xdr_u_quad_t)78 strong_alias_untyped(xdr_uint64_t,xdr_u_quad_t)
79
80 /* XDR 32bit integers */
81 bool_t
82 xdr_int32_t (XDR *xdrs, int32_t *lp)
83 {
84 switch (xdrs->x_op)
85 {
86 case XDR_ENCODE:
87 return XDR_PUTINT32 (xdrs, lp);
88 case XDR_DECODE:
89 return XDR_GETINT32 (xdrs, lp);
90 case XDR_FREE:
91 return TRUE;
92 default:
93 return FALSE;
94 }
95 }
96
97 /* XDR 32bit unsigned integers */
98 bool_t
xdr_uint32_t(XDR * xdrs,uint32_t * ulp)99 xdr_uint32_t (XDR *xdrs, uint32_t *ulp)
100 {
101 switch (xdrs->x_op)
102 {
103 case XDR_ENCODE:
104 return XDR_PUTINT32 (xdrs, (int32_t *) ulp);
105 case XDR_DECODE:
106 return XDR_GETINT32 (xdrs, (int32_t *) ulp);
107 case XDR_FREE:
108 return TRUE;
109 default:
110 return FALSE;
111 }
112 }
113
114 /* XDR 16bit integers */
115 bool_t
xdr_int16_t(XDR * xdrs,int16_t * ip)116 xdr_int16_t (XDR *xdrs, int16_t *ip)
117 {
118 int32_t t;
119
120 switch (xdrs->x_op)
121 {
122 case XDR_ENCODE:
123 t = (int32_t) *ip;
124 return XDR_PUTINT32 (xdrs, &t);
125 case XDR_DECODE:
126 if (!XDR_GETINT32 (xdrs, &t))
127 return FALSE;
128 *ip = (int16_t) t;
129 return TRUE;
130 case XDR_FREE:
131 return TRUE;
132 default:
133 return FALSE;
134 }
135 }
136
137 /* XDR 16bit unsigned integers */
138 bool_t
xdr_uint16_t(XDR * xdrs,uint16_t * uip)139 xdr_uint16_t (XDR *xdrs, uint16_t *uip)
140 {
141 uint32_t ut;
142
143 switch (xdrs->x_op)
144 {
145 case XDR_ENCODE:
146 ut = (uint32_t) *uip;
147 return XDR_PUTINT32 (xdrs, (int32_t *) &ut);
148 case XDR_DECODE:
149 if (!XDR_GETINT32 (xdrs, (int32_t *) &ut))
150 return FALSE;
151 *uip = (uint16_t) ut;
152 return TRUE;
153 case XDR_FREE:
154 return TRUE;
155 default:
156 return FALSE;
157 }
158 }
159
160 /* XDR 8bit integers */
161 bool_t
xdr_int8_t(XDR * xdrs,int8_t * ip)162 xdr_int8_t (XDR *xdrs, int8_t *ip)
163 {
164 int32_t t;
165
166 switch (xdrs->x_op)
167 {
168 case XDR_ENCODE:
169 t = (int32_t) *ip;
170 return XDR_PUTINT32 (xdrs, &t);
171 case XDR_DECODE:
172 if (!XDR_GETINT32 (xdrs, &t))
173 return FALSE;
174 *ip = (int8_t) t;
175 return TRUE;
176 case XDR_FREE:
177 return TRUE;
178 default:
179 return FALSE;
180 }
181 }
182
183 /* XDR 8bit unsigned integers */
184 bool_t
xdr_uint8_t(XDR * xdrs,uint8_t * uip)185 xdr_uint8_t (XDR *xdrs, uint8_t *uip)
186 {
187 uint32_t ut;
188
189 switch (xdrs->x_op)
190 {
191 case XDR_ENCODE:
192 ut = (uint32_t) *uip;
193 return XDR_PUTINT32 (xdrs, (int32_t *) &ut);
194 case XDR_DECODE:
195 if (!XDR_GETINT32 (xdrs, (int32_t *) &ut))
196 return FALSE;
197 *uip = (uint8_t) ut;
198 return TRUE;
199 case XDR_FREE:
200 return TRUE;
201 default:
202 return FALSE;
203 }
204 }
205