1 /*
2  * Copyright (c) 1990-1997 Sam Leffler
3  * Copyright (c) 1991-1997 Silicon Graphics, Inc.
4  *
5  * Permission to use, copy, modify, distribute, and sell this software and
6  * its documentation for any purpose is hereby granted without fee, provided
7  * that (i) the above copyright notices and this permission notice appear in
8  * all copies of the software and related documentation, and (ii) the names of
9  * Sam Leffler and Silicon Graphics may not be used in any advertising or
10  * publicity relating to the software without the specific, prior written
11  * permission of Sam Leffler and Silicon Graphics.
12  *
13  * THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND,
14  * EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY
15  * WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
16  *
17  * IN NO EVENT SHALL SAM LEFFLER OR SILICON GRAPHICS BE LIABLE FOR
18  * ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND,
19  * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
20  * WHETHER OR NOT ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF
21  * LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE
22  * OF THIS SOFTWARE.
23  */
24 
25 #ifndef _COMPAT_
26 #define _COMPAT_
27 /*
28  * This file contains a hodgepodge of definitions and
29  * declarations that are needed to provide compatibility
30  * between the native system and the base implementation
31  * that the library assumes.
32  *
33  * NB: This file is a mess.
34  */
35 
36 /*
37  * Setup basic type definitions and function declaratations.
38  */
39 
40 /*
41  * Simplify Acorn RISC OS identifier (to avoid confusion with Acorn RISC iX
42  * and with defunct Unix Risc OS)
43  * No need to specify __arm - hey, Acorn might port the OS, no problem here!
44  */
45 #ifdef __acornriscos
46 #undef __acornriscos
47 #endif
48 #if defined(__acorn) && defined(__riscos)
49 #define __acornriscos
50 #endif
51 
52 #include <stdio.h>
53 
54 #if defined(__PPCC__) || defined(__SC__) || defined(__MRC__)
55 #include <types.h>
56 #endif
57 
58 #if defined(VMS)
59 #include <file.h>
60 #include <unixio.h>
61 #elif !defined(__acornriscos)
62 #include <fcntl.h>
63 #endif
64 
65 /*
66  * This maze of checks controls defines or not the
67  * target system has BSD-style typdedefs declared in
68  * an include file and/or whether or not to include
69  * <unistd.h> to get the SEEK_* definitions.  Some
70  * additional includes are also done to pull in the
71  * appropriate definitions we're looking for.
72  */
73 #if defined(THINK_C) || defined(__PPCC__) || defined(__SC__) || defined(__MRC__)
74 #include <stdlib.h>
75 #define BSDTYPES
76 #define HAVE_UNISTD_H 0
77 #elif (defined(_WINDOWS) || defined(__WIN32__) || defined(_Windows) || defined(_WIN32)) && !defined(unix)
78 #define BSDTYPES
79 #elif defined(OS2_16) || defined(OS2_32)
80 #define BSDTYPES
81 #elif defined(__acornriscos)
82 #include <stdlib.h>
83 #define BSDTYPES
84 #define HAVE_UNISTD_H 0
85 #elif defined(VMS)
86 #define HAVE_UNISTD_H 0
87 #else
88 #define HAVE_UNISTD_H 1
89 #endif
90 
91 /*
92  * The library uses the ANSI C/POSIX SEEK_*
93  * definitions that should be defined in unistd.h
94  * (except on system where they are in stdio.h and
95  * there is no unistd.h).
96  */
97 #if !defined(SEEK_SET) && HAVE_UNISTD_H
98 #include <unistd.h>
99 #endif
100 
101 /*
102  * The library uses memset, memcpy, and memcmp.
103  * ANSI C and System V define these in string.h.
104  */
105 #include <string.h>
106 
107 /*
108  * The BSD typedefs are used throughout the library.
109  * If your system doesn't have them in <sys/types.h>,
110  * then define BSDTYPES in your Makefile.
111  */
112 #if defined(BSDTYPES)
113 # ifndef _BSDTYPES_DEFINED
114 #  ifndef __u_char_defined
115 typedef unsigned char u_char;
116 typedef unsigned short u_short;
117 typedef unsigned int u_int;
118 typedef unsigned long u_long;
119 #   define __u_char_defined
120 #  endif /* __u_char_defined */
121 #  define _BSDTYPES_DEFINED
122 # endif /* _BSDTYPES_DEFINED */
123 #endif /* BSDTYPES */
124 
125 /*
126  * dblparam_t is the type that a double precision
127  * floating point value will have on the parameter
128  * stack (when coerced by the compiler).
129  */
130 /* Note: on MacPowerPC "extended" is undefined. So only use it for 68K-Macs */
131 #if defined(__SC__) || defined(THINK_C)
132 typedef extended dblparam_t;
133 #else
134 typedef double dblparam_t;
135 #endif
136 
137 /*
138  * If your compiler supports inline functions, then
139  * set INLINE appropriately to get the known hotspots
140  * in the library expanded inline.
141  */
142 #if defined(__GNUC__)
143 #if defined(__STRICT_ANSI__)
144 #define INLINE  __inline__
145 #else
146 #define INLINE  inline
147 #endif
148 #else /* !__GNUC__ */
149 #define INLINE
150 #endif
151 
152 /*
153  * GLOBALDATA is a macro that is used to define global variables
154  * private to the library.  We use this indirection to hide
155  * brain-damage in VAXC (and GCC) under VAX/VMS.  In these
156  * environments the macro places the variable in a non-shareable
157  * program section, which ought to be done by default (sigh!)
158  *
159  * Apparently DEC are aware of the problem as this behaviour is the
160  * default under VMS on AXP.
161  *
162  * The GNU C variant is untested.
163  */
164 #if defined(VAX) && defined(VMS)
165 #if defined(VAXC)
166 #define GLOBALDATA(TYPE,NAME) extern noshare TYPE NAME
167 #endif
168 #if defined(__GNUC__)
169 #define GLOBALDATA(TYPE,NAME) extern TYPE NAME \
170         asm("_$$PsectAttributes_NOSHR$$" #NAME)
171 #endif
172 #else /* !VAX/VMS */
173 #define GLOBALDATA(TYPE,NAME) extern TYPE NAME
174 #endif
175 
176 #if defined(__acornriscos)
177 /*
178  * osfcn.h is part of C++Lib on Acorn C/C++, and as such can't be used
179  * on C alone. For that reason, the relevant functions are
180  * implemented in tif_acorn.c, and the elements from the header
181  * file are included here.
182  */
183 #if defined(__cplusplus)
184 #include <osfcn.h>
185 #else
186 #define O_RDONLY  0
187 #define O_WRONLY  1
188 #define O_RDWR    2
189 #define O_APPEND  8
190 #define O_CREAT   0x200
191 #define O_TRUNC   0x400
192 typedef long off_t;
193 extern int open(const char *name, int flags, int mode);
194 extern int close(int fd);
195 extern int write(int fd, const char *buf, int nbytes);
196 extern int read(int fd, char *buf, int nbytes);
197 extern off_t lseek(int fd, off_t offset, int whence);
198 extern int creat(const char *path, int mode);
199 #endif /* __cplusplus */
200 #endif /* __acornriscos */
201 
202 /* Bit and byte order, the default is MSB to LSB */
203 #ifdef VMS
204 #undef HOST_FILLORDER
205 #undef HOST_BIGENDIAN
206 #define HOST_FILLORDER FILLORDER_LSB2MSB
207 #define HOST_BIGENDIAN  0
208 #endif
209 
210 
211 #endif /* _COMPAT_ */
212