1 
2 /*
3  * Copyright (c) 2009, Sun Microsystems, Inc.
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are met:
8  * - Redistributions of source code must retain the above copyright notice,
9  *   this list of conditions and the following disclaimer.
10  * - Redistributions in binary form must reproduce the above copyright notice,
11  *   this list of conditions and the following disclaimer in the documentation
12  *   and/or other materials provided with the distribution.
13  * - Neither the name of Sun Microsystems, Inc. nor the names of its
14  *   contributors may be used to endorse or promote products derived
15  *   from this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 /*
31  * xdr_float.c, Generic XDR routines implementation.
32  *
33  * Copyright (C) 1984, Sun Microsystems, Inc.
34  *
35  * These are the "floating point" xdr routines used to (de)serialize
36  * most common data items.  See xdr.h for more info on the interface to
37  * xdr.
38  */
39 
40 #define _DEFAULT_SOURCE
41 #include <sys/types.h>
42 #include <rpc/types.h>
43 #include <rpc/xdr.h>
44 
45 #include "xdr_private.h"
46 
47 /*
48  * NB: Not portable.
49  * This routine works on machines with IEEE754 FP and Vaxen.
50  * Assume that xdr_private.h arranges things so that one of
51  *   1) __IEEE_LITTLE_ENDIAN
52  *   2) __IEEE_BIG_ENDIAN
53  *   3) __vax__
54  * is #defined.  Otherwise, expect errors.
55  */
56 #ifndef XDR_FLOAT_C
57 #define XDR_FLOAT_C
58 #endif
59 
60 #if defined(__IEEE_LITTLE_ENDIAN) || defined(__IEEE_BIG_ENDIAN)
61 
62 bool_t
xdr_float(XDR * xdrs,float * fp)63 xdr_float (XDR * xdrs,
64        float *fp)
65 {
66   switch (xdrs->x_op)
67     {
68 
69     case XDR_ENCODE:
70       return (XDR_PUTINT32 (xdrs, (int32_t *) fp));
71 
72     case XDR_DECODE:
73       return (XDR_GETINT32 (xdrs, (int32_t *) fp));
74 
75     case XDR_FREE:
76       return TRUE;
77     }
78   return FALSE;
79 }
80 
81 #if !defined(_DOUBLE_IS_32BITS)
82 bool_t
xdr_double(XDR * xdrs,double * dp)83 xdr_double (XDR * xdrs,
84 	double *dp)
85 {
86   int32_t *i32p;
87   bool_t rv;
88 
89   switch (xdrs->x_op)
90     {
91 
92     case XDR_ENCODE:
93       i32p = (int32_t *) (void *) dp;
94 #if defined(__IEEE_BIG_ENDIAN)
95       rv = XDR_PUTINT32 (xdrs, i32p);
96       if (!rv)
97         return (rv);
98       rv = XDR_PUTINT32 (xdrs, i32p + 1);
99 #else /* must be __IEEE_LITTLE_ENDIAN */
100       rv = XDR_PUTINT32 (xdrs, i32p + 1);
101       if (!rv)
102         return (rv);
103       rv = XDR_PUTINT32 (xdrs, i32p);
104 #endif /* __IEEE_LITTLE_ENDIAN */
105       return (rv);
106 
107     case XDR_DECODE:
108       i32p = (int32_t *) (void *) dp;
109 #if defined(__IEEE_BIG_ENDIAN)
110       rv = XDR_GETINT32 (xdrs, i32p);
111       if (!rv)
112         return (rv);
113       rv = XDR_GETINT32 (xdrs, i32p + 1);
114 #else /* must be __IEEE_LITTLE_ENDIAN */
115       rv = XDR_GETINT32 (xdrs, i32p + 1);
116       if (!rv)
117         return (rv);
118       rv = XDR_GETINT32 (xdrs, i32p);
119 #endif /* __IEEE_LITTLE_ENDIAN */
120       return (rv);
121 
122     case XDR_FREE:
123       return TRUE;
124     }
125   return FALSE;
126 }
127 #endif /* !_DOUBLE_IS_32BITS */
128 
129 #elif defined(__vax__)
130 #include "xdr_float_vax.c"
131 #endif
132 
133