xdr_intXX_t.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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, see
  14. <http://www.gnu.org/licenses/>. */
  15. #include <rpc/types.h>
  16. #include <rpc/xdr.h>
  17. /* XDR 64bit integers */
  18. bool_t
  19. xdr_int64_t (XDR *xdrs, int64_t *ip)
  20. {
  21. int32_t t1;
  22. /* This must be unsigned, otherwise we get problems with sign
  23. extension in the DECODE case. */
  24. uint32_t t2;
  25. switch (xdrs->x_op)
  26. {
  27. case XDR_ENCODE:
  28. t1 = (int32_t) ((*ip) >> 32);
  29. t2 = (int32_t) (*ip);
  30. return (XDR_PUTINT32(xdrs, &t1) && XDR_PUTINT32(xdrs, (int32_t *) &t2));
  31. case XDR_DECODE:
  32. if (!XDR_GETINT32(xdrs, &t1) || !XDR_GETINT32(xdrs, (int32_t *) &t2))
  33. return FALSE;
  34. *ip = ((int64_t) t1) << 32;
  35. *ip |= t2;
  36. return TRUE;
  37. case XDR_FREE:
  38. return TRUE;
  39. default:
  40. return FALSE;
  41. }
  42. }
  43. strong_alias_untyped(xdr_int64_t,xdr_quad_t)
  44. /* XDR 64bit unsigned integers */
  45. bool_t
  46. xdr_uint64_t (XDR *xdrs, uint64_t *uip)
  47. {
  48. uint32_t t1;
  49. uint32_t t2;
  50. switch (xdrs->x_op)
  51. {
  52. case XDR_ENCODE:
  53. t1 = (uint32_t) ((*uip) >> 32);
  54. t2 = (uint32_t) (*uip);
  55. return (XDR_PUTINT32 (xdrs, (int32_t *) &t1) &&
  56. XDR_PUTINT32(xdrs, (int32_t *) &t2));
  57. case XDR_DECODE:
  58. if (!XDR_GETINT32(xdrs, (int32_t *) &t1) ||
  59. !XDR_GETINT32(xdrs, (int32_t *) &t2))
  60. return FALSE;
  61. *uip = ((uint64_t) t1) << 32;
  62. *uip |= t2;
  63. return TRUE;
  64. case XDR_FREE:
  65. return TRUE;
  66. default:
  67. return FALSE;
  68. }
  69. }
  70. strong_alias_untyped(xdr_uint64_t,xdr_u_quad_t)
  71. /* XDR 32bit integers */
  72. bool_t
  73. xdr_int32_t (XDR *xdrs, int32_t *lp)
  74. {
  75. switch (xdrs->x_op)
  76. {
  77. case XDR_ENCODE:
  78. return XDR_PUTINT32 (xdrs, lp);
  79. case XDR_DECODE:
  80. return XDR_GETINT32 (xdrs, lp);
  81. case XDR_FREE:
  82. return TRUE;
  83. default:
  84. return FALSE;
  85. }
  86. }
  87. /* XDR 32bit unsigned integers */
  88. bool_t
  89. xdr_uint32_t (XDR *xdrs, uint32_t *ulp)
  90. {
  91. switch (xdrs->x_op)
  92. {
  93. case XDR_ENCODE:
  94. return XDR_PUTINT32 (xdrs, (int32_t *) ulp);
  95. case XDR_DECODE:
  96. return XDR_GETINT32 (xdrs, (int32_t *) ulp);
  97. case XDR_FREE:
  98. return TRUE;
  99. default:
  100. return FALSE;
  101. }
  102. }
  103. /* XDR 16bit integers */
  104. bool_t
  105. xdr_int16_t (XDR *xdrs, int16_t *ip)
  106. {
  107. int32_t t;
  108. switch (xdrs->x_op)
  109. {
  110. case XDR_ENCODE:
  111. t = (int32_t) *ip;
  112. return XDR_PUTINT32 (xdrs, &t);
  113. case XDR_DECODE:
  114. if (!XDR_GETINT32 (xdrs, &t))
  115. return FALSE;
  116. *ip = (int16_t) t;
  117. return TRUE;
  118. case XDR_FREE:
  119. return TRUE;
  120. default:
  121. return FALSE;
  122. }
  123. }
  124. /* XDR 16bit unsigned integers */
  125. bool_t
  126. xdr_uint16_t (XDR *xdrs, uint16_t *uip)
  127. {
  128. uint32_t ut;
  129. switch (xdrs->x_op)
  130. {
  131. case XDR_ENCODE:
  132. ut = (uint32_t) *uip;
  133. return XDR_PUTINT32 (xdrs, (int32_t *) &ut);
  134. case XDR_DECODE:
  135. if (!XDR_GETINT32 (xdrs, (int32_t *) &ut))
  136. return FALSE;
  137. *uip = (uint16_t) ut;
  138. return TRUE;
  139. case XDR_FREE:
  140. return TRUE;
  141. default:
  142. return FALSE;
  143. }
  144. }
  145. /* XDR 8bit integers */
  146. bool_t
  147. xdr_int8_t (XDR *xdrs, int8_t *ip)
  148. {
  149. int32_t t;
  150. switch (xdrs->x_op)
  151. {
  152. case XDR_ENCODE:
  153. t = (int32_t) *ip;
  154. return XDR_PUTINT32 (xdrs, &t);
  155. case XDR_DECODE:
  156. if (!XDR_GETINT32 (xdrs, &t))
  157. return FALSE;
  158. *ip = (int8_t) t;
  159. return TRUE;
  160. case XDR_FREE:
  161. return TRUE;
  162. default:
  163. return FALSE;
  164. }
  165. }
  166. /* XDR 8bit unsigned integers */
  167. bool_t
  168. xdr_uint8_t (XDR *xdrs, uint8_t *uip)
  169. {
  170. uint32_t ut;
  171. switch (xdrs->x_op)
  172. {
  173. case XDR_ENCODE:
  174. ut = (uint32_t) *uip;
  175. return XDR_PUTINT32 (xdrs, (int32_t *) &ut);
  176. case XDR_DECODE:
  177. if (!XDR_GETINT32 (xdrs, (int32_t *) &ut))
  178. return FALSE;
  179. *uip = (uint8_t) ut;
  180. return TRUE;
  181. case XDR_FREE:
  182. return TRUE;
  183. default:
  184. return FALSE;
  185. }
  186. }