Tooltalk fixes for OpenBSD. This consists mainly of #ifdefs, casts and some small...
[oweals/cde.git] / cde / lib / tt / lib / util / tt_xdr_utils.C
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these librararies and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 //%%  (c) Copyright 1993, 1994 Hewlett-Packard Company                  
24 //%%  (c) Copyright 1993, 1994 International Business Machines Corp.    
25 //%%  (c) Copyright 1993, 1994 Sun Microsystems, Inc.                   
26 //%%  (c) Copyright 1993, 1994 Novell, Inc.                             
27 //%%  $XConsortium: tt_xdr_utils.C /main/6 1996/08/29 18:08:20 drk $                                                    
28 /*
29  *
30  * tt_xdr_utils.cc
31  *
32  * Copyright (c) 1990 by Sun Microsystems, Inc.
33  */
34 #if defined(ultrix)
35 #include <rpc/types.h>
36 #define bool_t int
37 #endif
38 #include <rpc/rpc.h>
39 #include <util/tt_xdr_utils.h>
40 #include <memory.h>
41 #include "tt_options.h"
42
43 #if defined(CSRG_BASED)
44 #define XDR __rpc_xdr
45 #endif
46
47 typedef bool_t (*local_xdrproc_t)(XDR *, caddr_t *);
48
49 #ifndef OPT_XDR_LONG_TYPE
50 # define OPT_XDR_LONG_TYPE      long
51 #endif
52 static bool_t
53 tt_x_putlong(XDR *xp, OPT_XDR_LONG_TYPE *)
54 {
55     xp->x_handy += 4;
56     return TRUE;
57 }
58
59 static bool_t
60 /* The second argument is caddr_t and not void * in both SUN, DEC headers
61  * files.
62  * The third agrument is also wrong. Both SUN and DEC system header files
63  * expect int instead of u_int.
64  */
65 #if defined(CSRG_BASED)
66 tt_x_putbytes(XDR *xp, caddr_t, unsigned int len)
67 #else
68 tt_x_putbytes(XDR *xp, caddr_t, int len)
69 #endif
70 {
71     xp->x_handy += RNDUP (len);
72     return TRUE;
73 }
74
75 #if defined(ultrix) || defined(__osf__)
76 static int*
77 #elif defined(CSRG_BASED)
78 static int32_t*
79 #else
80 static long *
81 #endif
82 #if defined(CSRG_BASED)
83 tt_x_inline(XDR *xp, unsigned int len)
84 #else
85 tt_x_inline(XDR *xp, int len)
86 #endif
87 {
88         /* Be paranoid -- some code really expects inline to
89          * always succeed, so we keep a small buffer around
90          * just in case.  Not too paranoid, though -- it's
91          * legal to not support inline!
92          */
93     /* It is better to promote len to caddr_t than demote x_base to
94        int for 64 bit arch.
95     */
96     if (len > 0 && (caddr_t) len < xp->x_base) {
97         xp->x_handy += RNDUP (len);
98 #if defined(ultrix) || defined(__osf__)
99         return (int *) xp->x_private;
100 #elif defined(CSRG_BASED)
101         return (int32_t *) xp->x_private;
102 #else
103         return (long *) xp->x_private;
104 #endif
105     } else
106         return 0;
107 }
108
109
110 unsigned long
111 _tt_xdr_sizeof(xdrproc_t f, void *data)
112 {
113         _Tt_xdr_size_stream x;
114
115         if ((*(local_xdrproc_t)f) ((XDR *)x, (caddr_t *)data) == TRUE) {
116                 return x.getsize();
117         } else {
118                 return 0;
119         }
120 }
121
122 _Tt_xdr_size_stream::
123 _Tt_xdr_size_stream() {
124         memset ((char *)&ops, 0, sizeof ops);
125 #if defined(OPT_BUG_SUNOS_4) || defined(OPT_BUG_HPUX)
126         ops.x_putlong = (int (*)(...))tt_x_putlong;
127         ops.x_putbytes = (int (*)(...))tt_x_putbytes;
128         ops.x_inline = (long *(*)(...))tt_x_inline;
129 #elif defined(OPT_BUG_AIX)
130         ops.x_putlong = (int (*)(XDR *, long *))tt_x_putlong;
131         ops.x_putbytes = (int (*)(XDR *, caddr_t, u_int))tt_x_putbytes;
132         ops.x_inline = (long *(*)(XDR *, u_int))tt_x_inline;
133 #elif defined(OPT_BUG_SUNOS_5)
134         ops.x_putlong = tt_x_putlong;
135         ops.x_putbytes = (bool_t (*)(XDR *, caddr_t, int))tt_x_putbytes;
136         ops.x_inline = tt_x_inline;
137 #elif defined(CRAY)
138         ops.x_putlong = tt_x_putlong;
139         ops.x_putbytes = tt_x_putbytes;
140         ops.x_inline = (inline_t *(*)(...))tt_x_inline;
141 #elif defined(OPT_BUG_USL) || defined(OPT_BUG_UXP)
142         ops.x_putlong = tt_x_putlong;
143         ops.x_putbytes = (bool_t (*)(XDR *, caddr_t, u_int))  tt_x_putbytes;
144 #if defined(OPT_BUG_UW_1)
145         ops.x_inline = (long *(*)(struct __XDR *, const int)) tt_x_inline;
146 #else
147         ops.x_inline = (long *(*)(struct XDR *, int)) tt_x_inline;
148 #endif /* OPT_BUG_UW1 */
149 #else
150         ops.x_putlong = tt_x_putlong;
151         ops.x_putbytes = tt_x_putbytes;
152         ops.x_inline = tt_x_inline;
153 #endif  
154         xdrstream.x_op = XDR_ENCODE;
155         xdrstream.x_ops = &ops;
156         xdrstream.x_handy = 0;
157         xdrstream.x_private = (caddr_t) buf;
158         xdrstream.x_base = (caddr_t) sizeof buf;
159 }
160
161 _Tt_xdr_size_stream::
162 operator XDR *() {
163         return(&xdrstream);
164 }