]> git.ipfire.org Git - thirdparty/glibc.git/blame - sunrpc/xdr_intXX_t.c
[BZ #284, BZ #721]
[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
AJ
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, write to the Free
17 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18 02111-1307 USA. */
5713a71e
UD
19
20#include <rpc/types.h>
f20ba032
UD
21
22/* We play dirty tricks with aliases. */
23#define xdr_quad_t Xdr_quad_t
24#define xdr_u_quad_t Xdr_u_quad_t
5713a71e 25#include <rpc/xdr.h>
f20ba032
UD
26#undef xdr_quad_t
27#undef xdr_u_quad_t
28
5713a71e 29
50f301a8
AS
30/* XDR 64bit integers */
31bool_t
32xdr_int64_t (XDR *xdrs, int64_t *ip)
33{
9cfe5381 34 int32_t t1, t2;
50f301a8
AS
35
36 switch (xdrs->x_op)
37 {
38 case XDR_ENCODE:
39 t1 = (int32_t) ((*ip) >> 32);
40 t2 = (int32_t) (*ip);
41 return (XDR_PUTINT32(xdrs, &t1) && XDR_PUTINT32(xdrs, &t2));
42 case XDR_DECODE:
43 if (!XDR_GETINT32(xdrs, &t1) || !XDR_GETINT32(xdrs, &t2))
44 return FALSE;
45 *ip = ((int64_t) t1) << 32;
9cfe5381 46 *ip |= (uint32_t) t2; /* Avoid sign extension. */
50f301a8
AS
47 return TRUE;
48 case XDR_FREE:
49 return TRUE;
50 default:
51 return FALSE;
52 }
53}
f20ba032 54strong_alias (xdr_int64_t, xdr_quad_t)
50f301a8
AS
55
56/* XDR 64bit unsigned integers */
57bool_t
58xdr_uint64_t (XDR *xdrs, uint64_t *uip)
59{
60 uint32_t t1;
61 uint32_t t2;
62
63 switch (xdrs->x_op)
64 {
65 case XDR_ENCODE:
66 t1 = (uint32_t) ((*uip) >> 32);
67 t2 = (uint32_t) (*uip);
68 return (XDR_PUTINT32 (xdrs, (int32_t *) &t1) &&
69 XDR_PUTINT32(xdrs, (int32_t *) &t2));
70 case XDR_DECODE:
71 if (!XDR_GETINT32(xdrs, (int32_t *) &t1) ||
72 !XDR_GETINT32(xdrs, (int32_t *) &t2))
73 return FALSE;
74 *uip = ((uint64_t) t1) << 32;
75 *uip |= t2;
76 return TRUE;
77 case XDR_FREE:
78 return TRUE;
79 default:
80 return FALSE;
81 }
82}
f20ba032 83strong_alias (xdr_int64_t, xdr_u_quad_t)
50f301a8 84
5713a71e
UD
85/* XDR 32bit integers */
86bool_t
87xdr_int32_t (XDR *xdrs, int32_t *lp)
88{
89 switch (xdrs->x_op)
90 {
91 case XDR_ENCODE:
92 return XDR_PUTINT32 (xdrs, lp);
93 case XDR_DECODE:
94 return XDR_GETINT32 (xdrs, lp);
95 case XDR_FREE:
96 return TRUE;
97 default:
98 return FALSE;
99 }
100}
101
102/* XDR 32bit unsigned integers */
103bool_t
104xdr_uint32_t (XDR *xdrs, uint32_t *ulp)
105{
106 switch (xdrs->x_op)
107 {
5713a71e
UD
108 case XDR_ENCODE:
109 return XDR_PUTINT32 (xdrs, (int32_t *) ulp);
50f301a8
AS
110 case XDR_DECODE:
111 return XDR_GETINT32 (xdrs, (int32_t *) ulp);
5713a71e
UD
112 case XDR_FREE:
113 return TRUE;
114 default:
115 return FALSE;
116 }
117}
118
119/* XDR 16bit integers */
120bool_t
121xdr_int16_t (XDR *xdrs, int16_t *ip)
122{
123 int32_t t;
124
125 switch (xdrs->x_op)
126 {
127 case XDR_ENCODE:
128 t = (int32_t) *ip;
129 return XDR_PUTINT32 (xdrs, &t);
130 case XDR_DECODE:
131 if (!XDR_GETINT32 (xdrs, &t))
132 return FALSE;
133 *ip = (int16_t) t;
134 return TRUE;
135 case XDR_FREE:
136 return TRUE;
137 default:
138 return FALSE;
139 }
140}
141
142/* XDR 16bit unsigned integers */
143bool_t
144xdr_uint16_t (XDR *xdrs, uint16_t *uip)
145{
146 uint32_t ut;
147
148 switch (xdrs->x_op)
149 {
5713a71e 150 case XDR_ENCODE:
bdd5fccd
UD
151 ut = (uint32_t) *uip;
152 return XDR_PUTINT32 (xdrs, (int32_t *) &ut);
153 case XDR_DECODE:
154 if (!XDR_GETINT32 (xdrs, (int32_t *) &ut))
5713a71e
UD
155 return FALSE;
156 *uip = (uint16_t) ut;
157 return TRUE;
158 case XDR_FREE:
159 return TRUE;
160 default:
161 return FALSE;
162 }
163}
164
165/* XDR 8bit integers */
166bool_t
167xdr_int8_t (XDR *xdrs, int8_t *ip)
168{
169 int32_t t;
170
171 switch (xdrs->x_op)
172 {
173 case XDR_ENCODE:
174 t = (int32_t) *ip;
175 return XDR_PUTINT32 (xdrs, &t);
176 case XDR_DECODE:
177 if (!XDR_GETINT32 (xdrs, &t))
178 return FALSE;
179 *ip = (int8_t) t;
180 return TRUE;
181 case XDR_FREE:
182 return TRUE;
183 default:
184 return FALSE;
185 }
186}
187
188/* XDR 8bit unsigned integers */
189bool_t
190xdr_uint8_t (XDR *xdrs, uint8_t *uip)
191{
192 uint32_t ut;
193
194 switch (xdrs->x_op)
195 {
5713a71e 196 case XDR_ENCODE:
446e763b
AJ
197 ut = (uint32_t) *uip;
198 return XDR_PUTINT32 (xdrs, (int32_t *) &ut);
199 case XDR_DECODE:
200 if (!XDR_GETINT32 (xdrs, (int32_t *) &ut))
5713a71e
UD
201 return FALSE;
202 *uip = (uint8_t) ut;
203 return TRUE;
204 case XDR_FREE:
205 return TRUE;
206 default:
207 return FALSE;
208 }
209}