]> git.ipfire.org Git - thirdparty/glibc.git/blame - sunrpc/xdr_intXX_t.c
Merge branch 'elf-move'
[thirdparty/glibc.git] / sunrpc / xdr_intXX_t.c
CommitLineData
9cfe5381 1/* Copyright (c) 1998, 1999, 2000, 2004, 2005 Free Software Foundation, Inc.
5713a71e
UD
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
41bdb6e2
AJ
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.
5713a71e
UD
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
41bdb6e2 13 Lesser General Public License for more details.
5713a71e 14
41bdb6e2 15 You should have received a copy of the GNU Lesser General Public
59ba27a6
PE
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
5713a71e
UD
18
19#include <rpc/types.h>
f20ba032
UD
20
21/* We play dirty tricks with aliases. */
5713a71e 22#include <rpc/xdr.h>
f20ba032 23
5713a71e 24
50f301a8
AS
25/* XDR 64bit integers */
26bool_t
27xdr_int64_t (XDR *xdrs, int64_t *ip)
28{
9cfe5381 29 int32_t t1, t2;
50f301a8
AS
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, &t2));
37 case XDR_DECODE:
38 if (!XDR_GETINT32(xdrs, &t1) || !XDR_GETINT32(xdrs, &t2))
7b57bfe5 39 return FALSE;
50f301a8 40 *ip = ((int64_t) t1) << 32;
9cfe5381 41 *ip |= (uint32_t) t2; /* Avoid sign extension. */
50f301a8
AS
42 return TRUE;
43 case XDR_FREE:
44 return TRUE;
45 default:
46 return FALSE;
47 }
48}
7b57bfe5
UD
49libc_hidden_nolink (xdr_int64_t, GLIBC_2_1_1)
50
51bool_t
52xdr_quad_t (XDR *xdrs, quad_t *ip)
53{
54 return xdr_int64_t (xdrs, (int64_t *) ip);
55}
56libc_hidden_nolink (xdr_quad_t, GLIBC_2_3_4)
50f301a8
AS
57
58/* XDR 64bit unsigned integers */
59bool_t
60xdr_uint64_t (XDR *xdrs, uint64_t *uip)
61{
62 uint32_t t1;
63 uint32_t t2;
64
65 switch (xdrs->x_op)
66 {
67 case XDR_ENCODE:
68 t1 = (uint32_t) ((*uip) >> 32);
69 t2 = (uint32_t) (*uip);
70 return (XDR_PUTINT32 (xdrs, (int32_t *) &t1) &&
71 XDR_PUTINT32(xdrs, (int32_t *) &t2));
72 case XDR_DECODE:
73 if (!XDR_GETINT32(xdrs, (int32_t *) &t1) ||
74 !XDR_GETINT32(xdrs, (int32_t *) &t2))
7b57bfe5 75 return FALSE;
50f301a8
AS
76 *uip = ((uint64_t) t1) << 32;
77 *uip |= t2;
78 return TRUE;
79 case XDR_FREE:
80 return TRUE;
81 default:
82 return FALSE;
83 }
84}
7b57bfe5
UD
85libc_hidden_nolink (xdr_uint64_t, GLIBC_2_1_1)
86
87bool_t
88xdr_u_quad_t (XDR *xdrs, u_quad_t *ip)
89{
90 return xdr_uint64_t (xdrs, (uint64_t *) ip);
91}
92libc_hidden_nolink (xdr_u_quad_t, GLIBC_2_3_4)
50f301a8 93
5713a71e
UD
94/* XDR 32bit integers */
95bool_t
96xdr_int32_t (XDR *xdrs, int32_t *lp)
97{
98 switch (xdrs->x_op)
99 {
100 case XDR_ENCODE:
101 return XDR_PUTINT32 (xdrs, lp);
102 case XDR_DECODE:
103 return XDR_GETINT32 (xdrs, lp);
104 case XDR_FREE:
105 return TRUE;
106 default:
107 return FALSE;
108 }
109}
7b57bfe5 110libc_hidden_nolink (xdr_int32_t, GLIBC_2_1)
5713a71e
UD
111
112/* XDR 32bit unsigned integers */
113bool_t
114xdr_uint32_t (XDR *xdrs, uint32_t *ulp)
115{
116 switch (xdrs->x_op)
117 {
5713a71e
UD
118 case XDR_ENCODE:
119 return XDR_PUTINT32 (xdrs, (int32_t *) ulp);
50f301a8
AS
120 case XDR_DECODE:
121 return XDR_GETINT32 (xdrs, (int32_t *) ulp);
5713a71e
UD
122 case XDR_FREE:
123 return TRUE;
124 default:
125 return FALSE;
126 }
127}
7b57bfe5
UD
128#ifdef EXPORT_RPC_SYMBOLS
129libc_hidden_def (xdr_uint32_t)
130#else
131libc_hidden_nolink (xdr_uint32_t, GLIBC_2_1)
132#endif
5713a71e
UD
133
134/* XDR 16bit integers */
135bool_t
136xdr_int16_t (XDR *xdrs, int16_t *ip)
137{
138 int32_t t;
139
140 switch (xdrs->x_op)
141 {
142 case XDR_ENCODE:
143 t = (int32_t) *ip;
144 return XDR_PUTINT32 (xdrs, &t);
145 case XDR_DECODE:
146 if (!XDR_GETINT32 (xdrs, &t))
147 return FALSE;
148 *ip = (int16_t) t;
149 return TRUE;
150 case XDR_FREE:
151 return TRUE;
152 default:
153 return FALSE;
154 }
155}
7b57bfe5 156libc_hidden_nolink (xdr_int16_t, GLIBC_2_1)
5713a71e
UD
157
158/* XDR 16bit unsigned integers */
159bool_t
160xdr_uint16_t (XDR *xdrs, uint16_t *uip)
161{
162 uint32_t ut;
163
164 switch (xdrs->x_op)
165 {
5713a71e 166 case XDR_ENCODE:
bdd5fccd
UD
167 ut = (uint32_t) *uip;
168 return XDR_PUTINT32 (xdrs, (int32_t *) &ut);
169 case XDR_DECODE:
170 if (!XDR_GETINT32 (xdrs, (int32_t *) &ut))
5713a71e
UD
171 return FALSE;
172 *uip = (uint16_t) ut;
173 return TRUE;
174 case XDR_FREE:
175 return TRUE;
176 default:
177 return FALSE;
178 }
179}
7b57bfe5 180libc_hidden_nolink (xdr_uint16_t, GLIBC_2_1)
5713a71e
UD
181
182/* XDR 8bit integers */
183bool_t
184xdr_int8_t (XDR *xdrs, int8_t *ip)
185{
186 int32_t t;
187
188 switch (xdrs->x_op)
189 {
190 case XDR_ENCODE:
191 t = (int32_t) *ip;
192 return XDR_PUTINT32 (xdrs, &t);
193 case XDR_DECODE:
194 if (!XDR_GETINT32 (xdrs, &t))
195 return FALSE;
196 *ip = (int8_t) t;
197 return TRUE;
198 case XDR_FREE:
199 return TRUE;
200 default:
201 return FALSE;
202 }
203}
7b57bfe5 204libc_hidden_nolink (xdr_int8_t, GLIBC_2_1)
5713a71e
UD
205
206/* XDR 8bit unsigned integers */
207bool_t
208xdr_uint8_t (XDR *xdrs, uint8_t *uip)
209{
210 uint32_t ut;
211
212 switch (xdrs->x_op)
213 {
5713a71e 214 case XDR_ENCODE:
446e763b
AJ
215 ut = (uint32_t) *uip;
216 return XDR_PUTINT32 (xdrs, (int32_t *) &ut);
217 case XDR_DECODE:
218 if (!XDR_GETINT32 (xdrs, (int32_t *) &ut))
5713a71e
UD
219 return FALSE;
220 *uip = (uint8_t) ut;
221 return TRUE;
222 case XDR_FREE:
223 return TRUE;
224 default:
225 return FALSE;
226 }
227}
7b57bfe5 228libc_hidden_nolink (xdr_uint8_t, GLIBC_2_1)