convert-from-bsd-to-posix-string-and-memory-functions-20010807
[openafs.git] / src / rx / xdr_int64.c
1
2 /*
3  *  XDR routine for int64 (long long or struct)
4  */
5
6 #include <afsconfig.h>
7 #include <afs/param.h>
8
9 RCSID("$Header$");
10
11 #if defined(KERNEL) && !defined(UKERNEL)
12 #ifdef AFS_LINUX20_ENV
13 #include "../h/string.h"
14 #if 0
15 #define bzero(A,C) memset((A), 0, (C))
16 #endif
17 #else
18 #include <sys/param.h>
19 #include <sys/systm.h>
20 #endif
21 #else
22 #include <stdio.h>
23 #endif
24 #include "xdr.h"
25 #if defined(KERNEL) && !defined(UKERNEL)
26 #ifdef        AFS_DEC_ENV
27 #include <afs/longc_procs.h>
28 #endif
29 #endif
30
31 #ifdef AFS_64BIT_ENV
32 /*
33  * XDR afs_int64 integers
34  */
35 bool_t
36 xdr_int64(xdrs, ulp)
37         register XDR *xdrs;
38         afs_int64 *ulp;
39 {
40         static afs_int32 high;
41         static afs_uint32 low;
42
43         if (xdrs->x_op == XDR_DECODE) {
44                 if (!XDR_GETINT32(xdrs, (afs_int32 *) &high)) return (FALSE);
45                 if (!XDR_GETINT32(xdrs, (afs_int32 *) &low)) return (FALSE);
46                 *ulp = high;
47                 *ulp <<= 32;
48                 *ulp += low;
49                 return (TRUE);
50         }
51         if (xdrs->x_op == XDR_ENCODE) {
52                 high = (*ulp >> 32);
53                 low = *ulp & 0xFFFFFFFFL;
54                 if (!XDR_PUTINT32(xdrs, (afs_int32 *) &high)) return (FALSE);
55                 return (XDR_PUTINT32(xdrs, (afs_int32 *) &low));
56         }
57         if (xdrs->x_op == XDR_FREE)
58                 return (TRUE);
59         return (FALSE);
60 }
61
62 /*
63  * XDR afs_int64 integers
64  */
65 bool_t
66 xdr_uint64(xdrs, ulp)
67         register XDR *xdrs;
68         afs_uint64 *ulp;
69 {
70         static afs_uint32 high;
71         static afs_uint32 low;
72
73         if (xdrs->x_op == XDR_DECODE) {
74                 if (!XDR_GETINT32(xdrs, (afs_uint32 *) &high)) return (FALSE);
75                 if (!XDR_GETINT32(xdrs, (afs_uint32 *) &low)) return (FALSE);
76                 *ulp = high;
77                 *ulp <<= 32;
78                 *ulp += low;
79                 return (TRUE);
80         }
81         if (xdrs->x_op == XDR_ENCODE) {
82                 high = (*ulp >> 32);
83                 low = *ulp & 0xFFFFFFFFL;
84                 if (!XDR_PUTINT32(xdrs, (afs_uint32 *) &high)) return (FALSE);
85                 return (XDR_PUTINT32(xdrs, (afs_uint32 *) &low));
86         }
87         if (xdrs->x_op == XDR_FREE)
88                 return (TRUE);
89         return (FALSE);
90 }
91 #else /* AFS_64BIT_ENV */
92 /*
93  * XDR afs_int64 integers
94  */
95 bool_t
96 xdr_int64(xdrs, ulp)
97         register XDR *xdrs;
98         afs_int64 *ulp;
99 {
100         if (xdrs->x_op == XDR_DECODE) {
101                 if (!XDR_GETINT32(xdrs, (afs_int32 *) &ulp->high)) return (FALSE);
102                 return (XDR_GETINT32(xdrs, (afs_int32 *) &ulp->low));
103         }
104         if (xdrs->x_op == XDR_ENCODE) {
105                 if (!XDR_PUTINT32(xdrs, (afs_int32 *) &ulp->high)) return (FALSE);
106                 return (XDR_PUTINT32(xdrs, (afs_int32 *) &ulp->low));
107         }
108         if (xdrs->x_op == XDR_FREE)
109                 return (TRUE);
110         return (FALSE);
111 }
112
113 /*
114  * XDR afs_uint64 integers
115  */
116 bool_t
117 xdr_uint64(xdrs, ulp)
118         register XDR *xdrs;
119         afs_uint64 *ulp;
120 {
121         if (xdrs->x_op == XDR_DECODE) {
122                 if (!XDR_GETINT32(xdrs, (afs_uint32 *) &ulp->high)) return (FALSE);
123                 return (XDR_GETINT32(xdrs, (afs_uint32 *) &ulp->low));
124         }
125         if (xdrs->x_op == XDR_ENCODE) {
126                 if (!XDR_PUTINT32(xdrs, (afs_uint32 *) &ulp->high)) return (FALSE);
127                 return (XDR_PUTINT32(xdrs, (afs_uint32 *) &ulp->low));
128         }
129         if (xdrs->x_op == XDR_FREE)
130                 return (TRUE);
131         return (FALSE);
132 }
133 #endif /* AFS_64BIT_ENV */