1 /*
2  * Copyright (C) 1995 Advanced RISC Machines Limited. All rights reserved.
3  *
4  * This software may be freely used, copied, modified, and distributed
5  * provided that the above copyright notice is preserved in all copies of the
6  * software.
7  */
8 
9 
10 #ifndef _host_LOADED
11 #define _host_LOADED 1
12 
13 #include <stdio.h>
14 #include <stddef.h>
15 #include <stdlib.h>
16 
17 #ifndef SEEK_SET
18 #  define SEEK_SET  0
19 #endif
20 #ifndef SEEK_CUR
21 #  define SEEK_CUR  1
22 #endif
23 #ifndef SEEK_END
24 #  define SEEK_END  2
25 #endif
26 
27 /* The following for the benefit of compiling on SunOS */
28 #ifndef offsetof
29 #  define offsetof(T, member)  ((char *)&(((T *)0)->member) - (char *)0)
30 #endif
31 
32 /* A temporary sop to older compilers */
33 #if defined (__NetBSD__) || defined (unix)
34 #  ifndef __unix              /* (good for long-term portability?)  */
35 #    define __unix    1
36 #  endif
37 #endif
38 
39 #if defined(__unix)
40 /* Generic unix -- hopefully a split into other variants will not be    */
41 /* needed.  However, beware the 'bsd' test above and safe_toupper etc.  */
42 /* which cope with backwards (pre-posix/X/open) unix compatility.       */
43 #  define COMPILING_ON_UNIX     1
44 #endif
45 #if defined(_WIN32)
46 #  define COMPILING_ON_WIN32    1
47 #  if !defined(__CYGWIN__)
48 #    define COMPILING_ON_WINDOWS  1
49 #  endif
50 #endif
51 #if defined(_CONSOLE)
52 #  define COMPILING_ON_WINDOWS_CONSOLE 1
53 #  define COMPILING_ON_WINDOWS 1
54 #endif
55 /* The '(defined(__sparc) && defined(P_tmpdir)                     */
56 /* && !defined(__svr4__))' is to detect gcc on SunOS.              */
57 /* C++ compilers don't have to define __STDC__                     */
58 #if (defined(__sparc) && defined(P_tmpdir))
59 #  if defined(__svr4__)
60 #    define COMPILING_ON_SOLARIS
61 #  else
62 #    define COMPILING_ON_SUNOS
63 #  endif
64 #endif
65 #ifdef __hppa
66 #  define COMPILING_ON_HPUX
67 #endif
68 
69 /*
70  * The following typedefs may need alteration for obscure host machines.
71  */
72 #if defined(__alpha) && defined(__osf__) /* =========================== */
73 /* Under OSF the alpha has 64-bit pointers and 64-bit longs.            */
74 typedef                int   int32;
75 typedef unsigned       int   unsigned32;
76 /* IPtr and UPtr are 'ints of same size as pointer'.  Do not use in     */
77 /* new code.  Currently only used within 'ncc'.                         */
78 typedef          long  int   IPtr;
79 typedef unsigned long  int   UPtr;
80 
81 #else /* all hosts except alpha under OSF ============================= */
82 
83 typedef          long  int   int32;
84 typedef unsigned long  int   unsigned32;
85 /* IPtr and UPtr are 'ints of same size as pointer'.  Do not use in     */
86 /* new code.  Currently only used within 'ncc'.                         */
87 #define IPtr int32
88 #define UPtr unsigned32
89 #endif /* ============================================================= */
90 
91 typedef          short int   int16;
92 typedef unsigned short int   unsigned16;
93 typedef   signed       char  int8;
94 typedef unsigned       char  unsigned8;
95 
96 /* The following code defines the 'bool' type to be 'int' under C       */
97 /* and real 'bool' under C++.  It also avoids warnings such as          */
98 /* C++ keyword 'bool' used as identifier.  It can be overridden by      */
99 /* defining IMPLEMENT_BOOL_AS_ENUM or IMPLEMENT_BOOL_AS_INT.            */
100 #undef _bool
101 
102 #ifdef IMPLEMENT_BOOL_AS_ENUM
103    enum _bool { _false, _true };
104 #  define _bool enum _bool
105 #elif defined(IMPLEMENT_BOOL_AS_INT) || !defined(__cplusplus)
106 #  define _bool int
107 #  define _false 0
108 #  define _true 1
109 #endif
110 
111 #ifdef _bool
112 #  if defined(_MFC_VER) || defined(__CC_NORCROFT) /* When using MS Visual C/C++ v4.2 */
113 #    define bool _bool /* avoids "'bool' is reserved word" warning      */
114 #  else
115 #    ifndef bool
116        typedef _bool bool;
117 #    endif
118 #  endif
119 #  define true _true
120 #  define false _false
121 #endif
122 
123 #define YES   true
124 #define NO    false
125 #undef TRUE             /* some OSF headers define as 1                 */
126 #define TRUE  true
127 #undef FALSE            /* some OSF headers define as 1                 */
128 #define FALSE false
129 
130 /* 'uint' conflicts with some Unixen sys/types.h, so we now don't define it */
131 typedef unsigned8  uint8;
132 typedef unsigned16 uint16;
133 typedef unsigned32 uint32;
134 
135 typedef unsigned   Uint;
136 typedef unsigned8  Uint8;
137 typedef unsigned16 Uint16;
138 typedef unsigned32 Uint32;
139 
140 #ifdef ALPHA_TASO_SHORT_ON_OSF /* was __alpha && __osf.                 */
141 /* The following sets ArgvType for 64-bit pointers so that              */
142 /* DEC Unix (OSF) cc can be used with the -xtaso_short compiler option  */
143 /* to force pointers to be 32-bit.  Not currently used since most/all   */
144 /* ARM tools accept 32 or 64 bit pointers transparently.  See IPtr.     */
145 #pragma pointer_size (save)
146 #pragma pointer_size (long)
147 typedef char *ArgvType;
148 #pragma pointer_size (restore)
149 #else
150 typedef char *ArgvType;
151 #endif
152 
153 /*
154  * Rotate macros
155  */
156 #define ROL_32(val, n) \
157 ((((unsigned32)(val) << (n)) | ((unsigned32)(val) >> (32-(n)))) & 0xFFFFFFFFL)
158 #define ROR_32(val, n) \
159 ((((unsigned32)(val) >> (n)) | ((unsigned32)(val) << (32-(n)))) & 0xFFFFFFFFL)
160 
161 #ifdef COMPILING_ON_UNIX
162 #  define FOPEN_WB     "w"
163 #  define FOPEN_RB     "r"
164 #  define FOPEN_RWB    "r+"
165 #  ifndef __STDC__                     /* caveat RISCiX... */
166 #    define remove(file) unlink(file)  /* a horrid hack, but probably best? */
167 #  endif
168 #else
169 #  define FOPEN_WB     "wb"
170 #  define FOPEN_RB     "rb"
171 #  define FOPEN_RWB    "rb+"
172 #endif
173 
174 #ifndef FILENAME_MAX
175 #  define FILENAME_MAX 256
176 #endif
177 
178 #if (!defined(__STDC__) && !defined(__cplusplus)) || defined(COMPILING_ON_SUNOS)
179 /* Use bcopy rather than memmove, as memmove is not available.     */
180 /* There does not seem to be a header for bcopy.                   */
181 void bcopy(const char *src, char *dst, int length);
182 #  define memmove(d,s,l) bcopy(s,d,l)
183 
184 /* BSD/SUN don't have strtoul(), but then strtol() doesn't barf on */
185 /* overflow as required by ANSI... This bodge is horrid.           */
186 #  define strtoul(s, ptr, base) strtol(s, ptr, base)
187 
188 /* strtod is present in the C-library but is not in stdlib.h       */
189 extern double strtod(const char *str, char **ptr);
190 #endif
191 
192 /* For systems that do not define EXIT_SUCCESS and EXIT_FAILURE */
193 #ifndef EXIT_SUCCESS
194 #  define EXIT_SUCCESS           0
195 #endif
196 #ifndef EXIT_FAILURE
197 #  define EXIT_FAILURE           1
198 #endif
199 
200 #ifndef IGNORE
201 #define IGNORE(x) (x = x)  /* Silence compiler warnings for unused arguments */
202 #endif
203 
204 /* Define endian-ness of host */
205 
206 #if defined(__acorn) || defined(__mvs) || defined(_WIN32) || \
207   (defined(__alpha) && defined(__osf__))
208 #  define HOST_ENDIAN_LITTLE
209 #elif defined(__sparc) || defined(macintosh)
210 #  define HOST_ENDIAN_BIG
211 #else
212 #  define HOST_ENDIAN_UNKNOWN
213 #endif
214 
215 #endif
216 
217 /* Needs to be supplied by the host.  */
218 extern void Fail (const char *, ...);
219 
220 /* end of host.h */
221