OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [linux/] [uClibc/] [libc/] [inet/] [rpc/] [xdr_intXX_t.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1325 phoenix
/* 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
 
5
   The GNU C Library is free software; you can redistribute it and/or
6
   modify it under the terms of the GNU Lesser General Public
7
   License as published by the Free Software Foundation; either
8
   version 2.1 of the License, or (at your option) any later version.
9
 
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
   Lesser General Public License for more details.
14
 
15
   You should have received a copy of the GNU Lesser General Public
16
   License along with the GNU C Library; if not, write to the Free
17
   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18
   02111-1307 USA.  */
19
 
20
#include <rpc/types.h>
21
#include <rpc/xdr.h>
22
 
23
/* XDR 64bit integers */
24
bool_t
25
xdr_int64_t (XDR *xdrs, int64_t *ip)
26
{
27
  int32_t t1;
28
  /* This must be unsigned, otherwise we get problems with sign
29
     extension in the DECODE case.  */
30
  uint32_t t2;
31
 
32
  switch (xdrs->x_op)
33
    {
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 |= t2;
43
      return TRUE;
44
    case XDR_FREE:
45
      return TRUE;
46
    default:
47
      return FALSE;
48
    }
49
}
50
 
51
/* XDR 64bit unsigned integers */
52
bool_t
53
xdr_uint64_t (XDR *xdrs, uint64_t *uip)
54
{
55
  uint32_t t1;
56
  uint32_t t2;
57
 
58
  switch (xdrs->x_op)
59
    {
60
    case XDR_ENCODE:
61
      t1 = (uint32_t) ((*uip) >> 32);
62
      t2 = (uint32_t) (*uip);
63
      return (XDR_PUTINT32 (xdrs, (int32_t *) &t1) &&
64
              XDR_PUTINT32(xdrs, (int32_t *) &t2));
65
    case XDR_DECODE:
66
      if (!XDR_GETINT32(xdrs, (int32_t *) &t1) ||
67
          !XDR_GETINT32(xdrs, (int32_t *) &t2))
68
        return FALSE;
69
      *uip = ((uint64_t) t1) << 32;
70
      *uip |= t2;
71
      return TRUE;
72
    case XDR_FREE:
73
      return TRUE;
74
    default:
75
      return FALSE;
76
    }
77
}
78
 
79
/* XDR 32bit integers */
80
bool_t
81
xdr_int32_t (XDR *xdrs, int32_t *lp)
82
{
83
  switch (xdrs->x_op)
84
    {
85
    case XDR_ENCODE:
86
      return XDR_PUTINT32 (xdrs, lp);
87
    case XDR_DECODE:
88
      return XDR_GETINT32 (xdrs, lp);
89
    case XDR_FREE:
90
      return TRUE;
91
    default:
92
      return FALSE;
93
    }
94
}
95
 
96
/* XDR 32bit unsigned integers */
97
bool_t
98
xdr_uint32_t (XDR *xdrs, uint32_t *ulp)
99
{
100
  switch (xdrs->x_op)
101
    {
102
    case XDR_ENCODE:
103
      return XDR_PUTINT32 (xdrs, (int32_t *) ulp);
104
    case XDR_DECODE:
105
      return XDR_GETINT32 (xdrs, (int32_t *) ulp);
106
    case XDR_FREE:
107
      return TRUE;
108
    default:
109
      return FALSE;
110
    }
111
}
112
 
113
/* XDR 16bit integers */
114
bool_t
115
xdr_int16_t (XDR *xdrs, int16_t *ip)
116
{
117
  int32_t t;
118
 
119
  switch (xdrs->x_op)
120
    {
121
    case XDR_ENCODE:
122
      t = (int32_t) *ip;
123
      return XDR_PUTINT32 (xdrs, &t);
124
    case XDR_DECODE:
125
      if (!XDR_GETINT32 (xdrs, &t))
126
        return FALSE;
127
      *ip = (int16_t) t;
128
      return TRUE;
129
    case XDR_FREE:
130
      return TRUE;
131
    default:
132
      return FALSE;
133
    }
134
}
135
 
136
/* XDR 16bit unsigned integers */
137
bool_t
138
xdr_uint16_t (XDR *xdrs, uint16_t *uip)
139
{
140
  uint32_t ut;
141
 
142
  switch (xdrs->x_op)
143
    {
144
    case XDR_ENCODE:
145
      ut = (uint32_t) *uip;
146
      return XDR_PUTINT32 (xdrs, (int32_t *) &ut);
147
    case XDR_DECODE:
148
      if (!XDR_GETINT32 (xdrs, (int32_t *) &ut))
149
        return FALSE;
150
      *uip = (uint16_t) ut;
151
      return TRUE;
152
    case XDR_FREE:
153
      return TRUE;
154
    default:
155
      return FALSE;
156
    }
157
}
158
 
159
/* XDR 8bit integers */
160
bool_t
161
xdr_int8_t (XDR *xdrs, int8_t *ip)
162
{
163
  int32_t t;
164
 
165
  switch (xdrs->x_op)
166
    {
167
    case XDR_ENCODE:
168
      t = (int32_t) *ip;
169
      return XDR_PUTINT32 (xdrs, &t);
170
    case XDR_DECODE:
171
      if (!XDR_GETINT32 (xdrs, &t))
172
        return FALSE;
173
      *ip = (int8_t) t;
174
      return TRUE;
175
    case XDR_FREE:
176
      return TRUE;
177
    default:
178
      return FALSE;
179
    }
180
}
181
 
182
/* XDR 8bit unsigned integers */
183
bool_t
184
xdr_uint8_t (XDR *xdrs, uint8_t *uip)
185
{
186
  uint32_t ut;
187
 
188
  switch (xdrs->x_op)
189
    {
190
    case XDR_ENCODE:
191
      ut = (uint32_t) *uip;
192
      return XDR_PUTINT32 (xdrs, (int32_t *) &ut);
193
    case XDR_DECODE:
194
      if (!XDR_GETINT32 (xdrs, (int32_t *) &ut))
195
        return FALSE;
196
      *uip = (uint8_t) ut;
197
      return TRUE;
198
    case XDR_FREE:
199
      return TRUE;
200
    default:
201
      return FALSE;
202
    }
203
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.