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