xdr_intXX_t.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. /* Copyright (c) 1998, 1999, 2000 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.
  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.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, write to the Free
  14. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  15. 02111-1307 USA. */
  16. #include <rpc/types.h>
  17. #include <rpc/xdr.h>
  18. /* XDR 64bit integers */
  19. bool_t
  20. xdr_int64_t (XDR *xdrs, int64_t *ip)
  21. {
  22. int32_t t1;
  23. /* This must be unsigned, otherwise we get problems with sign
  24. extension in the DECODE case. */
  25. uint32_t t2;
  26. switch (xdrs->x_op)
  27. {
  28. case XDR_ENCODE:
  29. t1 = (int32_t) ((*ip) >> 32);
  30. t2 = (int32_t) (*ip);
  31. return (XDR_PUTINT32(xdrs, &t1) && XDR_PUTINT32(xdrs, (int32_t *) &t2));
  32. case XDR_DECODE:
  33. if (!XDR_GETINT32(xdrs, &t1) || !XDR_GETINT32(xdrs, (int32_t *) &t2))
  34. return FALSE;
  35. *ip = ((int64_t) t1) << 32;
  36. *ip |= t2;
  37. return TRUE;
  38. case XDR_FREE:
  39. return TRUE;
  40. default:
  41. return FALSE;
  42. }
  43. }
  44. strong_alias_untyped(xdr_int64_t,xdr_quad_t)
  45. /* XDR 64bit unsigned integers */
  46. bool_t
  47. xdr_uint64_t (XDR *xdrs, uint64_t *uip)
  48. {
  49. uint32_t t1;
  50. uint32_t t2;
  51. switch (xdrs->x_op)
  52. {
  53. case XDR_ENCODE:
  54. t1 = (uint32_t) ((*uip) >> 32);
  55. t2 = (uint32_t) (*uip);
  56. return (XDR_PUTINT32 (xdrs, (int32_t *) &t1) &&
  57. XDR_PUTINT32(xdrs, (int32_t *) &t2));
  58. case XDR_DECODE:
  59. if (!XDR_GETINT32(xdrs, (int32_t *) &t1) ||
  60. !XDR_GETINT32(xdrs, (int32_t *) &t2))
  61. return FALSE;
  62. *uip = ((uint64_t) t1) << 32;
  63. *uip |= t2;
  64. return TRUE;
  65. case XDR_FREE:
  66. return TRUE;
  67. default:
  68. return FALSE;
  69. }
  70. }
  71. strong_alias_untyped(xdr_uint64_t,xdr_u_quad_t)
  72. /* XDR 32bit integers */
  73. bool_t
  74. xdr_int32_t (XDR *xdrs, int32_t *lp)
  75. {
  76. switch (xdrs->x_op)
  77. {
  78. case XDR_ENCODE:
  79. return XDR_PUTINT32 (xdrs, lp);
  80. case XDR_DECODE:
  81. return XDR_GETINT32 (xdrs, lp);
  82. case XDR_FREE:
  83. return TRUE;
  84. default:
  85. return FALSE;
  86. }
  87. }
  88. /* XDR 32bit unsigned integers */
  89. bool_t
  90. xdr_uint32_t (XDR *xdrs, uint32_t *ulp)
  91. {
  92. switch (xdrs->x_op)
  93. {
  94. case XDR_ENCODE:
  95. return XDR_PUTINT32 (xdrs, (int32_t *) ulp);
  96. case XDR_DECODE:
  97. return XDR_GETINT32 (xdrs, (int32_t *) ulp);
  98. case XDR_FREE:
  99. return TRUE;
  100. default:
  101. return FALSE;
  102. }
  103. }
  104. /* XDR 16bit integers */
  105. bool_t
  106. xdr_int16_t (XDR *xdrs, int16_t *ip)
  107. {
  108. int32_t t;
  109. switch (xdrs->x_op)
  110. {
  111. case XDR_ENCODE:
  112. t = (int32_t) *ip;
  113. return XDR_PUTINT32 (xdrs, &t);
  114. case XDR_DECODE:
  115. if (!XDR_GETINT32 (xdrs, &t))
  116. return FALSE;
  117. *ip = (int16_t) t;
  118. return TRUE;
  119. case XDR_FREE:
  120. return TRUE;
  121. default:
  122. return FALSE;
  123. }
  124. }
  125. /* XDR 16bit unsigned integers */
  126. bool_t
  127. xdr_uint16_t (XDR *xdrs, uint16_t *uip)
  128. {
  129. uint32_t ut;
  130. switch (xdrs->x_op)
  131. {
  132. case XDR_ENCODE:
  133. ut = (uint32_t) *uip;
  134. return XDR_PUTINT32 (xdrs, (int32_t *) &ut);
  135. case XDR_DECODE:
  136. if (!XDR_GETINT32 (xdrs, (int32_t *) &ut))
  137. return FALSE;
  138. *uip = (uint16_t) ut;
  139. return TRUE;
  140. case XDR_FREE:
  141. return TRUE;
  142. default:
  143. return FALSE;
  144. }
  145. }
  146. /* XDR 8bit integers */
  147. bool_t
  148. xdr_int8_t (XDR *xdrs, int8_t *ip)
  149. {
  150. int32_t t;
  151. switch (xdrs->x_op)
  152. {
  153. case XDR_ENCODE:
  154. t = (int32_t) *ip;
  155. return XDR_PUTINT32 (xdrs, &t);
  156. case XDR_DECODE:
  157. if (!XDR_GETINT32 (xdrs, &t))
  158. return FALSE;
  159. *ip = (int8_t) t;
  160. return TRUE;
  161. case XDR_FREE:
  162. return TRUE;
  163. default:
  164. return FALSE;
  165. }
  166. }
  167. /* XDR 8bit unsigned integers */
  168. bool_t
  169. xdr_uint8_t (XDR *xdrs, uint8_t *uip)
  170. {
  171. uint32_t ut;
  172. switch (xdrs->x_op)
  173. {
  174. case XDR_ENCODE:
  175. ut = (uint32_t) *uip;
  176. return XDR_PUTINT32 (xdrs, (int32_t *) &ut);
  177. case XDR_DECODE:
  178. if (!XDR_GETINT32 (xdrs, (int32_t *) &ut))
  179. return FALSE;
  180. *uip = (uint8_t) ut;
  181. return TRUE;
  182. case XDR_FREE:
  183. return TRUE;
  184. default:
  185. return FALSE;
  186. }
  187. }