xref: /original-bsd/sys/nfs/xdr_subs.h (revision 614f1308)
1 /*
2  * Copyright (c) 1989 The Regents of the University of California.
3  * All rights reserved.
4  *
5  * This code is derived from software contributed to Berkeley by
6  * Rick Macklem at The University of Guelph.
7  *
8  * %sccs.include.redist.c%
9  *
10  *	@(#)xdr_subs.h	7.4 (Berkeley) 01/14/92
11  */
12 
13 /*
14  * Macros used for conversion to/from xdr representation by nfs...
15  * These use the MACHINE DEPENDENT routines ntohl, htonl
16  * As defined by "XDR: External Data Representation Standard" RFC1014
17  */
18 #if BYTE_ORDER == LITTLE_ENDIAN
19 #define fxdr_unsigned(t, v)	((t)ntohl((long)(v)))
20 #define	fxdr_time(f, t)	{ \
21 	((struct timeval *)(t))->tv_sec = \
22 		ntohl(((struct timeval *)(f))->tv_sec); \
23 	((struct timeval *)(t))->tv_usec = \
24 		ntohl(((struct timeval *)(f))->tv_usec); \
25 }
26 
27 /*
28  * To handle quad conversions, define a struct of two longs and use
29  * ntohl and htonl. Maybe someday there should be ntohq and htonq?
30  */
31 union _hq {
32 	quad_t	hq;
33 	struct {
34 		long val[2];
35 	} lq;
36 };
37 #define	fxdr_hyper(f, t) { \
38 	((union _hq *)(t))->lq.val[1] = ntohl(((union _hq *)(f))->lq.val[0]); \
39 	((union _hq *)(t))->lq.val[0] = ntohl(((union _hq *)(f))->lq.val[1]); \
40 }
41 #define	txdr_hyper(f, t) { \
42 	((union _hq *)(t))->lq.val[0] = htonl(((union _hq *)(f))->lq.val[1]); \
43 	((union _hq *)(t))->lq.val[1] = htonl(((union _hq *)(f))->lq.val[0]); \
44 }
45 
46 #define	txdr_unsigned(v)	(htonl((long)(v)))
47 #define	txdr_time(f, t)	{ \
48 	((struct timeval *)(t))->tv_sec = \
49 		htonl(((struct timeval *)(f))->tv_sec); \
50 	((struct timeval *)(t))->tv_usec = \
51 		htonl(((struct timeval *)(f))->tv_usec); \
52 }
53 #else	/* BIG_ENDIAN */
54 #define fxdr_unsigned(t, v)	((t)(v))
55 #define	fxdr_time(f, t) \
56 	*((struct timeval *)(t)) = *((struct timeval *)(f))
57 #define	fxdr_hyper(f, t) \
58 	*((quad_t *)(t)) = *((quad_t *)(f))
59 
60 #define	txdr_unsigned(v)	((long)(v))
61 #define	txdr_time(f, t) \
62 	*((struct timeval *)(t)) = *((struct timeval *)(f))
63 #define	txdr_hyper(f, t) \
64 	*((quad_t *)(t)) = *((quad_t *)(f))
65 #endif	/* ENDIAN */
66