Updated to fedora-glibc-20041218T1131
[glibc.git] / sunrpc / xdr_intXX_t.c
blob9d2f92e10d74bcc1774f93979c5e650c648646f6
1 /* Copyright (c) 1998, 1999, 2000, 2004 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.
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.
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.
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. */
20 #include <rpc/types.h>
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
25 #include <rpc/xdr.h>
26 #undef xdr_quad_t
27 #undef xdr_u_quad_t
30 /* XDR 64bit integers */
31 bool_t
32 xdr_int64_t (XDR *xdrs, int64_t *ip)
34 int32_t t1;
35 /* This must be unsigned, otherwise we get problems with sign
36 extension in the DECODE case. */
37 uint32_t t2;
39 switch (xdrs->x_op)
41 case XDR_ENCODE:
42 t1 = (int32_t) ((*ip) >> 32);
43 t2 = (int32_t) (*ip);
44 return (XDR_PUTINT32(xdrs, &t1) && XDR_PUTINT32(xdrs, &t2));
45 case XDR_DECODE:
46 if (!XDR_GETINT32(xdrs, &t1) || !XDR_GETINT32(xdrs, &t2))
47 return FALSE;
48 *ip = ((int64_t) t1) << 32;
49 *ip |= t2;
50 return TRUE;
51 case XDR_FREE:
52 return TRUE;
53 default:
54 return FALSE;
57 strong_alias (xdr_int64_t, xdr_quad_t)
59 /* XDR 64bit unsigned integers */
60 bool_t
61 xdr_uint64_t (XDR *xdrs, uint64_t *uip)
63 uint32_t t1;
64 uint32_t t2;
66 switch (xdrs->x_op)
68 case XDR_ENCODE:
69 t1 = (uint32_t) ((*uip) >> 32);
70 t2 = (uint32_t) (*uip);
71 return (XDR_PUTINT32 (xdrs, (int32_t *) &t1) &&
72 XDR_PUTINT32(xdrs, (int32_t *) &t2));
73 case XDR_DECODE:
74 if (!XDR_GETINT32(xdrs, (int32_t *) &t1) ||
75 !XDR_GETINT32(xdrs, (int32_t *) &t2))
76 return FALSE;
77 *uip = ((uint64_t) t1) << 32;
78 *uip |= t2;
79 return TRUE;
80 case XDR_FREE:
81 return TRUE;
82 default:
83 return FALSE;
86 strong_alias (xdr_int64_t, xdr_u_quad_t)
88 /* XDR 32bit integers */
89 bool_t
90 xdr_int32_t (XDR *xdrs, int32_t *lp)
92 switch (xdrs->x_op)
94 case XDR_ENCODE:
95 return XDR_PUTINT32 (xdrs, lp);
96 case XDR_DECODE:
97 return XDR_GETINT32 (xdrs, lp);
98 case XDR_FREE:
99 return TRUE;
100 default:
101 return FALSE;
105 /* XDR 32bit unsigned integers */
106 bool_t
107 xdr_uint32_t (XDR *xdrs, uint32_t *ulp)
109 switch (xdrs->x_op)
111 case XDR_ENCODE:
112 return XDR_PUTINT32 (xdrs, (int32_t *) ulp);
113 case XDR_DECODE:
114 return XDR_GETINT32 (xdrs, (int32_t *) ulp);
115 case XDR_FREE:
116 return TRUE;
117 default:
118 return FALSE;
122 /* XDR 16bit integers */
123 bool_t
124 xdr_int16_t (XDR *xdrs, int16_t *ip)
126 int32_t t;
128 switch (xdrs->x_op)
130 case XDR_ENCODE:
131 t = (int32_t) *ip;
132 return XDR_PUTINT32 (xdrs, &t);
133 case XDR_DECODE:
134 if (!XDR_GETINT32 (xdrs, &t))
135 return FALSE;
136 *ip = (int16_t) t;
137 return TRUE;
138 case XDR_FREE:
139 return TRUE;
140 default:
141 return FALSE;
145 /* XDR 16bit unsigned integers */
146 bool_t
147 xdr_uint16_t (XDR *xdrs, uint16_t *uip)
149 uint32_t ut;
151 switch (xdrs->x_op)
153 case XDR_ENCODE:
154 ut = (uint32_t) *uip;
155 return XDR_PUTINT32 (xdrs, (int32_t *) &ut);
156 case XDR_DECODE:
157 if (!XDR_GETINT32 (xdrs, (int32_t *) &ut))
158 return FALSE;
159 *uip = (uint16_t) ut;
160 return TRUE;
161 case XDR_FREE:
162 return TRUE;
163 default:
164 return FALSE;
168 /* XDR 8bit integers */
169 bool_t
170 xdr_int8_t (XDR *xdrs, int8_t *ip)
172 int32_t t;
174 switch (xdrs->x_op)
176 case XDR_ENCODE:
177 t = (int32_t) *ip;
178 return XDR_PUTINT32 (xdrs, &t);
179 case XDR_DECODE:
180 if (!XDR_GETINT32 (xdrs, &t))
181 return FALSE;
182 *ip = (int8_t) t;
183 return TRUE;
184 case XDR_FREE:
185 return TRUE;
186 default:
187 return FALSE;
191 /* XDR 8bit unsigned integers */
192 bool_t
193 xdr_uint8_t (XDR *xdrs, uint8_t *uip)
195 uint32_t ut;
197 switch (xdrs->x_op)
199 case XDR_ENCODE:
200 ut = (uint32_t) *uip;
201 return XDR_PUTINT32 (xdrs, (int32_t *) &ut);
202 case XDR_DECODE:
203 if (!XDR_GETINT32 (xdrs, (int32_t *) &ut))
204 return FALSE;
205 *uip = (uint8_t) ut;
206 return TRUE;
207 case XDR_FREE:
208 return TRUE;
209 default:
210 return FALSE;