source: trunk/libs/newlib/src/newlib/libc/xdr/xdr_float.c @ 444

Last change on this file since 444 was 444, checked in by satin@…, 6 years ago

add newlib,libalmos-mkh, restructure shared_syscalls.h and mini-libc

File size: 3.6 KB
Line 
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#include <sys/types.h>
41#include <rpc/types.h>
42#include <rpc/xdr.h>
43
44#include "xdr_private.h"
45
46/*
47 * NB: Not portable.
48 * This routine works on machines with IEEE754 FP and Vaxen.
49 * Assume that xdr_private.h arranges things so that one of
50 *   1) __IEEE_LITTLE_ENDIAN
51 *   2) __IEEE_BIG_ENDIAN
52 *   3) __vax__
53 * is #defined.  Otherwise, expect errors.
54 */
55#ifndef XDR_FLOAT_C
56#define XDR_FLOAT_C
57#endif
58
59#if defined(__IEEE_LITTLE_ENDIAN) || defined(__IEEE_BIG_ENDIAN)
60
61bool_t
62xdr_float (XDR * xdrs,
63       float *fp)
64{
65  switch (xdrs->x_op)
66    {
67
68    case XDR_ENCODE:
69      return (XDR_PUTINT32 (xdrs, (int32_t *) fp));
70
71    case XDR_DECODE:
72      return (XDR_GETINT32 (xdrs, (int32_t *) fp));
73
74    case XDR_FREE:
75      return TRUE;
76    }
77  return FALSE;
78}
79
80#if !defined(_DOUBLE_IS_32BITS)
81bool_t
82xdr_double (XDR * xdrs,
83        double *dp)
84{
85  int32_t *i32p;
86  bool_t rv;
87
88  switch (xdrs->x_op)
89    {
90
91    case XDR_ENCODE:
92      i32p = (int32_t *) (void *) dp;
93#if defined(__IEEE_BIG_ENDIAN)
94      rv = XDR_PUTINT32 (xdrs, i32p);
95      if (!rv)
96        return (rv);
97      rv = XDR_PUTINT32 (xdrs, i32p + 1);
98#else /* must be __IEEE_LITTLE_ENDIAN */
99      rv = XDR_PUTINT32 (xdrs, i32p + 1);
100      if (!rv)
101        return (rv);
102      rv = XDR_PUTINT32 (xdrs, i32p);
103#endif /* __IEEE_LITTLE_ENDIAN */
104      return (rv);
105
106    case XDR_DECODE:
107      i32p = (int32_t *) (void *) dp;
108#if defined(__IEEE_BIG_ENDIAN)
109      rv = XDR_GETINT32 (xdrs, i32p);
110      if (!rv)
111        return (rv);
112      rv = XDR_GETINT32 (xdrs, i32p + 1);
113#else /* must be __IEEE_LITTLE_ENDIAN */
114      rv = XDR_GETINT32 (xdrs, i32p + 1);
115      if (!rv)
116        return (rv);
117      rv = XDR_GETINT32 (xdrs, i32p);
118#endif /* __IEEE_LITTLE_ENDIAN */
119      return (rv);
120
121    case XDR_FREE:
122      return TRUE;
123    }
124  return FALSE;
125}
126#endif /* !_DOUBLE_IS_32BITS */
127
128#elif defined(__vax__)
129#include "xdr_float_vax.c"
130#endif
131
Note: See TracBrowser for help on using the repository browser.