nscd: Use time_t for return type of addgetnetgrentX
[glibc.git] / sunrpc / xdr_intXX_t.c
blobc591e24e7d1e81660b075524b67396686e439a5c
1 /* Copyright (c) 1998-2024 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <https://www.gnu.org/licenses/>. */
18 #include <rpc/types.h>
20 /* We play dirty tricks with aliases. */
21 #include <rpc/xdr.h>
23 #include <stdint.h>
24 #include <shlib-compat.h>
26 /* XDR 64bit integers */
27 bool_t
28 xdr_int64_t (XDR *xdrs, int64_t *ip)
30 int32_t t1, t2;
32 switch (xdrs->x_op)
34 case XDR_ENCODE:
35 t1 = (int32_t) ((*ip) >> 32);
36 t2 = (int32_t) (*ip);
37 return (XDR_PUTINT32(xdrs, &t1) && XDR_PUTINT32(xdrs, &t2));
38 case XDR_DECODE:
39 if (!XDR_GETINT32(xdrs, &t1) || !XDR_GETINT32(xdrs, &t2))
40 return FALSE;
41 *ip = ((int64_t) t1) << 32;
42 *ip |= (uint32_t) t2; /* Avoid sign extension. */
43 return TRUE;
44 case XDR_FREE:
45 return TRUE;
46 default:
47 return FALSE;
50 libc_hidden_nolink_sunrpc (xdr_int64_t, GLIBC_2_1_1)
52 bool_t
53 xdr_quad_t (XDR *xdrs, quad_t *ip)
55 return xdr_int64_t (xdrs, (int64_t *) ip);
57 libc_hidden_nolink_sunrpc (xdr_quad_t, GLIBC_2_3_4)
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 libc_hidden_nolink_sunrpc (xdr_uint64_t, GLIBC_2_1_1)
88 bool_t
89 xdr_u_quad_t (XDR *xdrs, u_quad_t *ip)
91 return xdr_uint64_t (xdrs, (uint64_t *) ip);
93 libc_hidden_nolink_sunrpc (xdr_u_quad_t, GLIBC_2_3_4)
95 /* XDR 32bit integers */
96 bool_t
97 xdr_int32_t (XDR *xdrs, int32_t *lp)
99 switch (xdrs->x_op)
101 case XDR_ENCODE:
102 return XDR_PUTINT32 (xdrs, lp);
103 case XDR_DECODE:
104 return XDR_GETINT32 (xdrs, lp);
105 case XDR_FREE:
106 return TRUE;
107 default:
108 return FALSE;
111 libc_hidden_nolink_sunrpc (xdr_int32_t, GLIBC_2_1)
113 /* XDR 32bit unsigned integers */
114 bool_t
115 xdr_uint32_t (XDR *xdrs, uint32_t *ulp)
117 switch (xdrs->x_op)
119 case XDR_ENCODE:
120 return XDR_PUTINT32 (xdrs, (int32_t *) ulp);
121 case XDR_DECODE:
122 return XDR_GETINT32 (xdrs, (int32_t *) ulp);
123 case XDR_FREE:
124 return TRUE;
125 default:
126 return FALSE;
129 #ifdef EXPORT_RPC_SYMBOLS
130 libc_hidden_def (xdr_uint32_t)
131 #else
132 libc_hidden_nolink_sunrpc (xdr_uint32_t, GLIBC_2_1)
133 #endif
135 /* XDR 16bit integers */
136 bool_t
137 xdr_int16_t (XDR *xdrs, int16_t *ip)
139 int32_t t;
141 switch (xdrs->x_op)
143 case XDR_ENCODE:
144 t = (int32_t) *ip;
145 return XDR_PUTINT32 (xdrs, &t);
146 case XDR_DECODE:
147 if (!XDR_GETINT32 (xdrs, &t))
148 return FALSE;
149 *ip = (int16_t) t;
150 return TRUE;
151 case XDR_FREE:
152 return TRUE;
153 default:
154 return FALSE;
157 libc_hidden_nolink_sunrpc (xdr_int16_t, GLIBC_2_1)
159 /* XDR 16bit unsigned integers */
160 bool_t
161 xdr_uint16_t (XDR *xdrs, uint16_t *uip)
163 uint32_t ut;
165 switch (xdrs->x_op)
167 case XDR_ENCODE:
168 ut = (uint32_t) *uip;
169 return XDR_PUTINT32 (xdrs, (int32_t *) &ut);
170 case XDR_DECODE:
171 if (!XDR_GETINT32 (xdrs, (int32_t *) &ut))
172 return FALSE;
173 *uip = (uint16_t) ut;
174 return TRUE;
175 case XDR_FREE:
176 return TRUE;
177 default:
178 return FALSE;
181 libc_hidden_nolink_sunrpc (xdr_uint16_t, GLIBC_2_1)
183 /* XDR 8bit integers */
184 bool_t
185 xdr_int8_t (XDR *xdrs, int8_t *ip)
187 int32_t t;
189 switch (xdrs->x_op)
191 case XDR_ENCODE:
192 t = (int32_t) *ip;
193 return XDR_PUTINT32 (xdrs, &t);
194 case XDR_DECODE:
195 if (!XDR_GETINT32 (xdrs, &t))
196 return FALSE;
197 *ip = (int8_t) t;
198 return TRUE;
199 case XDR_FREE:
200 return TRUE;
201 default:
202 return FALSE;
205 libc_hidden_nolink_sunrpc (xdr_int8_t, GLIBC_2_1)
207 /* XDR 8bit unsigned integers */
208 bool_t
209 xdr_uint8_t (XDR *xdrs, uint8_t *uip)
211 uint32_t ut;
213 switch (xdrs->x_op)
215 case XDR_ENCODE:
216 ut = (uint32_t) *uip;
217 return XDR_PUTINT32 (xdrs, (int32_t *) &ut);
218 case XDR_DECODE:
219 if (!XDR_GETINT32 (xdrs, (int32_t *) &ut))
220 return FALSE;
221 *uip = (uint8_t) ut;
222 return TRUE;
223 case XDR_FREE:
224 return TRUE;
225 default:
226 return FALSE;
229 libc_hidden_nolink_sunrpc (xdr_uint8_t, GLIBC_2_1)