Back to index

glibc  2.9
xdr_intXX_t.c
Go to the documentation of this file.
00001 /* Copyright (c) 1998, 1999, 2000, 2004, 2005 Free Software Foundation, Inc.
00002    This file is part of the GNU C Library.
00003    Contributed by Thorsten Kukuk <kukuk@vt.uni-paderborn.de>, 1998.
00004 
00005    The GNU C Library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public
00007    License as published by the Free Software Foundation; either
00008    version 2.1 of the License, or (at your option) any later version.
00009 
00010    The GNU C Library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Lesser General Public License for more details.
00014 
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with the GNU C Library; if not, write to the Free
00017    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00018    02111-1307 USA.  */
00019 
00020 #include <rpc/types.h>
00021 
00022 /* We play dirty tricks with aliases.  */
00023 #define xdr_quad_t Xdr_quad_t
00024 #define xdr_u_quad_t Xdr_u_quad_t
00025 #include <rpc/xdr.h>
00026 #undef xdr_quad_t
00027 #undef xdr_u_quad_t
00028 
00029 
00030 /* XDR 64bit integers */
00031 bool_t
00032 xdr_int64_t (XDR *xdrs, int64_t *ip)
00033 {
00034   int32_t t1, t2;
00035 
00036   switch (xdrs->x_op)
00037     {
00038     case XDR_ENCODE:
00039       t1 = (int32_t) ((*ip) >> 32);
00040       t2 = (int32_t) (*ip);
00041       return (XDR_PUTINT32(xdrs, &t1) && XDR_PUTINT32(xdrs, &t2));
00042     case XDR_DECODE:
00043       if (!XDR_GETINT32(xdrs, &t1) || !XDR_GETINT32(xdrs, &t2))
00044         return FALSE;
00045       *ip = ((int64_t) t1) << 32;
00046       *ip |= (uint32_t) t2; /* Avoid sign extension.  */
00047       return TRUE;
00048     case XDR_FREE:
00049       return TRUE;
00050     default:
00051       return FALSE;
00052     }
00053 }
00054 strong_alias (xdr_int64_t, xdr_quad_t)
00055 
00056 /* XDR 64bit unsigned integers */
00057 bool_t
00058 xdr_uint64_t (XDR *xdrs, uint64_t *uip)
00059 {
00060   uint32_t t1;
00061   uint32_t t2;
00062 
00063   switch (xdrs->x_op)
00064     {
00065     case XDR_ENCODE:
00066       t1 = (uint32_t) ((*uip) >> 32);
00067       t2 = (uint32_t) (*uip);
00068       return (XDR_PUTINT32 (xdrs, (int32_t *) &t1) &&
00069              XDR_PUTINT32(xdrs, (int32_t *) &t2));
00070     case XDR_DECODE:
00071       if (!XDR_GETINT32(xdrs, (int32_t *) &t1) ||
00072          !XDR_GETINT32(xdrs, (int32_t *) &t2))
00073         return FALSE;
00074       *uip = ((uint64_t) t1) << 32;
00075       *uip |= t2;
00076       return TRUE;
00077     case XDR_FREE:
00078       return TRUE;
00079     default:
00080       return FALSE;
00081     }
00082 }
00083 strong_alias (xdr_int64_t, xdr_u_quad_t)
00084 
00085 /* XDR 32bit integers */
00086 bool_t
00087 xdr_int32_t (XDR *xdrs, int32_t *lp)
00088 {
00089   switch (xdrs->x_op)
00090     {
00091     case XDR_ENCODE:
00092       return XDR_PUTINT32 (xdrs, lp);
00093     case XDR_DECODE:
00094       return XDR_GETINT32 (xdrs, lp);
00095     case XDR_FREE:
00096       return TRUE;
00097     default:
00098       return FALSE;
00099     }
00100 }
00101 
00102 /* XDR 32bit unsigned integers */
00103 bool_t
00104 xdr_uint32_t (XDR *xdrs, uint32_t *ulp)
00105 {
00106   switch (xdrs->x_op)
00107     {
00108     case XDR_ENCODE:
00109       return XDR_PUTINT32 (xdrs, (int32_t *) ulp);
00110     case XDR_DECODE:
00111       return XDR_GETINT32 (xdrs, (int32_t *) ulp);
00112     case XDR_FREE:
00113       return TRUE;
00114     default:
00115       return FALSE;
00116     }
00117 }
00118 
00119 /* XDR 16bit integers */
00120 bool_t
00121 xdr_int16_t (XDR *xdrs, int16_t *ip)
00122 {
00123   int32_t t;
00124 
00125   switch (xdrs->x_op)
00126     {
00127     case XDR_ENCODE:
00128       t = (int32_t) *ip;
00129       return XDR_PUTINT32 (xdrs, &t);
00130     case XDR_DECODE:
00131       if (!XDR_GETINT32 (xdrs, &t))
00132        return FALSE;
00133       *ip = (int16_t) t;
00134       return TRUE;
00135     case XDR_FREE:
00136       return TRUE;
00137     default:
00138       return FALSE;
00139     }
00140 }
00141 
00142 /* XDR 16bit unsigned integers */
00143 bool_t
00144 xdr_uint16_t (XDR *xdrs, uint16_t *uip)
00145 {
00146   uint32_t ut;
00147 
00148   switch (xdrs->x_op)
00149     {
00150     case XDR_ENCODE:
00151       ut = (uint32_t) *uip;
00152       return XDR_PUTINT32 (xdrs, (int32_t *) &ut);
00153     case XDR_DECODE:
00154       if (!XDR_GETINT32 (xdrs, (int32_t *) &ut))
00155        return FALSE;
00156       *uip = (uint16_t) ut;
00157       return TRUE;
00158     case XDR_FREE:
00159       return TRUE;
00160     default:
00161       return FALSE;
00162     }
00163 }
00164 
00165 /* XDR 8bit integers */
00166 bool_t
00167 xdr_int8_t (XDR *xdrs, int8_t *ip)
00168 {
00169   int32_t t;
00170 
00171   switch (xdrs->x_op)
00172     {
00173     case XDR_ENCODE:
00174       t = (int32_t) *ip;
00175       return XDR_PUTINT32 (xdrs, &t);
00176     case XDR_DECODE:
00177       if (!XDR_GETINT32 (xdrs, &t))
00178        return FALSE;
00179       *ip = (int8_t) t;
00180       return TRUE;
00181     case XDR_FREE:
00182       return TRUE;
00183     default:
00184       return FALSE;
00185     }
00186 }
00187 
00188 /* XDR 8bit unsigned integers */
00189 bool_t
00190 xdr_uint8_t (XDR *xdrs, uint8_t *uip)
00191 {
00192   uint32_t ut;
00193 
00194   switch (xdrs->x_op)
00195     {
00196     case XDR_ENCODE:
00197       ut = (uint32_t) *uip;
00198       return XDR_PUTINT32 (xdrs, (int32_t *) &ut);
00199     case XDR_DECODE:
00200       if (!XDR_GETINT32 (xdrs, (int32_t *) &ut))
00201        return FALSE;
00202       *uip = (uint8_t) ut;
00203       return TRUE;
00204     case XDR_FREE:
00205       return TRUE;
00206     default:
00207       return FALSE;
00208     }
00209 }