Update.
[glibc.git] / sunrpc / xdr_intXX_t.c
blobe50859e2aaf7ce1676d0ae74578b9e288a2fb5a1
1 /* Copyright (c) 1998, 1999 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 Library General Public License as
7 published by the Free Software Foundation; either version 2 of the
8 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 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public
16 License along with the GNU C Library; see the file COPYING.LIB. If not,
17 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA. */
20 #include <rpc/types.h>
21 #include <rpc/xdr.h>
23 /* XDR 64bit integers */
24 bool_t
25 xdr_int64_t (XDR *xdrs, int64_t *ip)
27 int32_t t1;
28 int32_t t2;
30 switch (xdrs->x_op)
32 case XDR_ENCODE:
33 t1 = (int32_t) ((*ip) >> 32);
34 t2 = (int32_t) (*ip);
35 return (XDR_PUTINT32(xdrs, &t1) && XDR_PUTINT32(xdrs, &t2));
36 case XDR_DECODE:
37 if (!XDR_GETINT32(xdrs, &t1) || !XDR_GETINT32(xdrs, &t2))
38 return FALSE;
39 *ip = ((int64_t) t1) << 32;
40 *ip |= t2;
41 return TRUE;
42 case XDR_FREE:
43 return TRUE;
44 default:
45 return FALSE;
49 /* XDR 64bit unsigned integers */
50 bool_t
51 xdr_uint64_t (XDR *xdrs, uint64_t *uip)
53 uint32_t t1;
54 uint32_t t2;
56 switch (xdrs->x_op)
58 case XDR_ENCODE:
59 t1 = (uint32_t) ((*uip) >> 32);
60 t2 = (uint32_t) (*uip);
61 return (XDR_PUTINT32 (xdrs, (int32_t *) &t1) &&
62 XDR_PUTINT32(xdrs, (int32_t *) &t2));
63 case XDR_DECODE:
64 if (!XDR_GETINT32(xdrs, (int32_t *) &t1) ||
65 !XDR_GETINT32(xdrs, (int32_t *) &t2))
66 return FALSE;
67 *uip = ((uint64_t) t1) << 32;
68 *uip |= t2;
69 return TRUE;
70 case XDR_FREE:
71 return TRUE;
72 default:
73 return FALSE;
77 /* XDR 32bit integers */
78 bool_t
79 xdr_int32_t (XDR *xdrs, int32_t *lp)
81 switch (xdrs->x_op)
83 case XDR_ENCODE:
84 return XDR_PUTINT32 (xdrs, lp);
85 case XDR_DECODE:
86 return XDR_GETINT32 (xdrs, lp);
87 case XDR_FREE:
88 return TRUE;
89 default:
90 return FALSE;
94 /* XDR 32bit unsigned integers */
95 bool_t
96 xdr_uint32_t (XDR *xdrs, uint32_t *ulp)
98 switch (xdrs->x_op)
100 case XDR_ENCODE:
101 return XDR_PUTINT32 (xdrs, (int32_t *) ulp);
102 case XDR_DECODE:
103 return XDR_GETINT32 (xdrs, (int32_t *) ulp);
104 case XDR_FREE:
105 return TRUE;
106 default:
107 return FALSE;
111 /* XDR 16bit integers */
112 bool_t
113 xdr_int16_t (XDR *xdrs, int16_t *ip)
115 int32_t t;
117 switch (xdrs->x_op)
119 case XDR_ENCODE:
120 t = (int32_t) *ip;
121 return XDR_PUTINT32 (xdrs, &t);
122 case XDR_DECODE:
123 if (!XDR_GETINT32 (xdrs, &t))
124 return FALSE;
125 *ip = (int16_t) t;
126 return TRUE;
127 case XDR_FREE:
128 return TRUE;
129 default:
130 return FALSE;
134 /* XDR 16bit unsigned integers */
135 bool_t
136 xdr_uint16_t (XDR *xdrs, uint16_t *uip)
138 uint32_t ut;
140 switch (xdrs->x_op)
142 case XDR_DECODE:
143 ut = (uint32_t) *uip;
144 return XDR_GETINT32 (xdrs, (int32_t *) &ut);
145 case XDR_ENCODE:
146 if (!XDR_PUTINT32 (xdrs, (int32_t *) &ut))
147 return FALSE;
148 *uip = (uint16_t) ut;
149 return TRUE;
150 case XDR_FREE:
151 return TRUE;
152 default:
153 return FALSE;
157 /* XDR 8bit integers */
158 bool_t
159 xdr_int8_t (XDR *xdrs, int8_t *ip)
161 int32_t t;
163 switch (xdrs->x_op)
165 case XDR_ENCODE:
166 t = (int32_t) *ip;
167 return XDR_PUTINT32 (xdrs, &t);
168 case XDR_DECODE:
169 if (!XDR_GETINT32 (xdrs, &t))
170 return FALSE;
171 *ip = (int8_t) t;
172 return TRUE;
173 case XDR_FREE:
174 return TRUE;
175 default:
176 return FALSE;
180 /* XDR 8bit unsigned integers */
181 bool_t
182 xdr_uint8_t (XDR *xdrs, uint8_t *uip)
184 uint32_t ut;
186 switch (xdrs->x_op)
188 case XDR_DECODE:
189 ut = (uint32_t) *uip;
190 return XDR_GETINT32 (xdrs, (int32_t *) &ut);
191 case XDR_ENCODE:
192 if (!XDR_PUTINT32 (xdrs, (int32_t *) &ut))
193 return FALSE;
194 *uip = (uint8_t) ut;
195 return TRUE;
196 case XDR_FREE:
197 return TRUE;
198 default:
199 return FALSE;