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