2 |
7u83 |
1 |
/*
|
|
|
2 |
Crown Copyright (c) 1997
|
|
|
3 |
|
|
|
4 |
This TenDRA(r) Computer Program is subject to Copyright
|
|
|
5 |
owned by the United Kingdom Secretary of State for Defence
|
|
|
6 |
acting through the Defence Evaluation and Research Agency
|
|
|
7 |
(DERA). It is made available to Recipients with a
|
|
|
8 |
royalty-free licence for its use, reproduction, transfer
|
|
|
9 |
to other parties and amendment for any purpose not excluding
|
|
|
10 |
product development provided that any such use et cetera
|
|
|
11 |
shall be deemed to be acceptance of the following conditions:-
|
|
|
12 |
|
|
|
13 |
(1) Its Recipients shall ensure that this Notice is
|
|
|
14 |
reproduced upon any copies or amended versions of it;
|
|
|
15 |
|
|
|
16 |
(2) Any amended version of it shall be clearly marked to
|
|
|
17 |
show both the nature of and the organisation responsible
|
|
|
18 |
for the relevant amendment or amendments;
|
|
|
19 |
|
|
|
20 |
(3) Its onward transfer from a recipient to another
|
|
|
21 |
party shall be deemed to be that party's acceptance of
|
|
|
22 |
these conditions;
|
|
|
23 |
|
|
|
24 |
(4) DERA gives no warranty or assurance as to its
|
|
|
25 |
quality or suitability for any purpose and DERA accepts
|
|
|
26 |
no liability whatsoever in relation to any use to which
|
|
|
27 |
it may be put.
|
|
|
28 |
*/
|
|
|
29 |
|
|
|
30 |
|
|
|
31 |
/**** os-interface.h --- Primitive definitions.
|
|
|
32 |
*
|
|
|
33 |
** Author: Steve Folkes <smf@hermes.mod.uk>
|
|
|
34 |
*
|
|
|
35 |
**** Commentary:
|
|
|
36 |
*
|
|
|
37 |
***=== INTRODUCTION =========================================================
|
|
|
38 |
*
|
|
|
39 |
* This file specifies an interface to the host system's C library, compiler
|
|
|
40 |
* and operating system. It provides definitions of basic types, constants
|
|
|
41 |
* and macros, and declarations of functions, that can be used by other
|
|
|
42 |
* components of the program.
|
|
|
43 |
*
|
|
|
44 |
* This file (and others in this directory) makes use of several macros to
|
|
|
45 |
* turn on certain features. These macros are listed below. In each case
|
|
|
46 |
* there is a macro that begins with ``FS_NO_'' instead of ``FS_'' that turns
|
|
|
47 |
* the feature off; if both are defined, the ``FS_NO_'' macro takes
|
|
|
48 |
* precedence, and the feature is turned off. In addition, the ``FS_NO_STDC''
|
|
|
49 |
* macro may be used to turn off the ``__STDC__'' macro (in the cases where
|
|
|
50 |
* the system isn't really ANSI compliant), and the ``FS_NO_FILE_INFO'' macro
|
|
|
51 |
* should be defined if the ``__FILE__'' or ``__LINE__'' macros are
|
|
|
52 |
* unsupported.
|
|
|
53 |
*
|
|
|
54 |
* FS_FAST
|
|
|
55 |
*
|
|
|
56 |
* This should be defined if you want the program to use macros in place of
|
|
|
57 |
* some function calls. This will generally speed up the program (although
|
|
|
58 |
* this is not guaranteed). It is incompatible with ``FS_SHORTNAMES''. It
|
|
|
59 |
* also turns off the assertion checking (unless ``FS_ASSERT'' is also
|
|
|
60 |
* defined).
|
|
|
61 |
*
|
|
|
62 |
* FS_SHORTNAMES
|
|
|
63 |
*
|
|
|
64 |
* This is a hack for systems that cannot cope with long external identifier
|
|
|
65 |
* names. It includes the file "shortnames.h" which should macro define all
|
|
|
66 |
* external identifiers to be a suitable short name. It is incompatible with
|
|
|
67 |
* ``FS_FAST''.
|
|
|
68 |
*
|
|
|
69 |
* FS_ASSERT
|
|
|
70 |
*
|
|
|
71 |
* This should be defined if you want assertion checking enabled. This is on
|
|
|
72 |
* by default, unless ``FS_FAST'' is defined, so it is only really useful to
|
|
|
73 |
* define this if you have also defined ``FS_FAST'', but still want assertions
|
|
|
74 |
* to be checked. It is possible that less assertions will be checked, as
|
|
|
75 |
* some of the "inlined" functions may have lost their assertions in the
|
|
|
76 |
* macro version.
|
|
|
77 |
*
|
|
|
78 |
* FS_STDC_HASH
|
|
|
79 |
*
|
|
|
80 |
* This should be defined if the system supports ANSI C style macro hash
|
|
|
81 |
* syntax (``#'' and ``##''). It is automatically defined if the ``__STDC__''
|
|
|
82 |
* macro is defined.
|
|
|
83 |
*
|
|
|
84 |
* FS_PROTOTYPES
|
|
|
85 |
*
|
|
|
86 |
* This should be defined if the system supports ANSI C style function
|
|
|
87 |
* prototypes. It is automatically defined if the ``__STDC__'' macro is
|
|
|
88 |
* defined.
|
|
|
89 |
*
|
|
|
90 |
* FS_VOID_PTR
|
|
|
91 |
*
|
|
|
92 |
* This should be defined if the system supports ``void *'' as a generic
|
|
|
93 |
* pointer. If this is not the case, then ``char *'' is used instead. It is
|
|
|
94 |
* automatically defined if the ``__STDC__'' macro is defined.
|
|
|
95 |
*
|
|
|
96 |
* FS_VOLATILE
|
|
|
97 |
*
|
|
|
98 |
* This should be defined if this system supports the ANSI C ``volatile''
|
|
|
99 |
* keyword. It is automatically defined if the ``__STDC__'' macro is defined.
|
|
|
100 |
*
|
|
|
101 |
* FS_CONST
|
|
|
102 |
*
|
|
|
103 |
* This should be defined if this system supports the ANSI C ``const''
|
|
|
104 |
* keyword. It is automatically defined if the ``__STDC__'' macro is defined.
|
|
|
105 |
*
|
|
|
106 |
* FS_UNION_INIT
|
|
|
107 |
*
|
|
|
108 |
* This should be defined if this system supports the ANSI C union
|
|
|
109 |
* initialisation. It is automatically defined if the ``__STDC__'' macro is
|
|
|
110 |
* defined.
|
|
|
111 |
*
|
|
|
112 |
* FS_ENUM
|
|
|
113 |
*
|
|
|
114 |
* This should be defined if this system supports enumerated types. It is
|
|
|
115 |
* automatically defined if ``__STDC__'' is defined. This macro needs to be
|
|
|
116 |
* tested wherever an enumeration type is declared, and if enumeration types
|
|
|
117 |
* are not supported, then an integer must be used instead.
|
|
|
118 |
*
|
|
|
119 |
* FS_ANSI_ENVIRON
|
|
|
120 |
*
|
|
|
121 |
* This should be defined if the system has an ANSI C compliant standard
|
|
|
122 |
* library. If this is not the case, then an attempt is made to approximate
|
|
|
123 |
* that library. It is automatically defined if the ``__STDC__'' macro is
|
|
|
124 |
* defined to be ``1''.
|
|
|
125 |
*
|
|
|
126 |
* FS_BINARY_STDIO
|
|
|
127 |
*
|
|
|
128 |
* This should be defined if the system supports the "b" modifier to the
|
|
|
129 |
* standard library ``fopen'' function. It is automatically defined if
|
|
|
130 |
* ``FS_ANSI_ENVIRON'' is defined.
|
|
|
131 |
*
|
|
|
132 |
* FS_STRERROR
|
|
|
133 |
*
|
|
|
134 |
* This should be defined if this system supports the ANSI ``strerror''
|
|
|
135 |
* function for getting a textual description of a system error message. It
|
|
|
136 |
* is automatically defined if ``FS_ANSI_ENVIRON'' is defined.
|
|
|
137 |
*
|
|
|
138 |
* FS_SYS_ERRLIST
|
|
|
139 |
*
|
|
|
140 |
* This should be defined if this system supports ``sys_nerr'' and
|
|
|
141 |
* ``sys_errlist'' for getting a textual description of the current system
|
|
|
142 |
* error. If the ``FS_STRERROR'' macro is defined, then the ANSI ``strerror''
|
|
|
143 |
* function will be used instead (overiding this macro). If neither macro is
|
|
|
144 |
* defined, then the error number will be used as the message.
|
|
|
145 |
*
|
|
|
146 |
* FS_MKDIR
|
|
|
147 |
*
|
|
|
148 |
* This should be defined if this system supports the POSIX ``mkdir''
|
|
|
149 |
* function.
|
|
|
150 |
*
|
|
|
151 |
* As well as the feature switch macros, there are some portability option
|
|
|
152 |
* macros as well. These provide values for types and constants when the type
|
|
|
153 |
* cannot be otherwise deduced. These macros are ignored when the correct
|
|
|
154 |
* value can be obtained automatically (this generally means on an ANSI
|
|
|
155 |
* compliant system).
|
|
|
156 |
*
|
|
|
157 |
* PO_SIZE_T_TYPE
|
|
|
158 |
*
|
|
|
159 |
* The ``sizeof'' operator returns a value of type ``size_t''. In an ANSI C
|
|
|
160 |
* compliant standard library, this type should be defined in <stddef.h>. If
|
|
|
161 |
* the machine doesn't have an ANSI C compliant standard library, then this
|
|
|
162 |
* macro should specify the type of ``size_t''. If no definition is provided,
|
|
|
163 |
* and the environment is not ANSI C compliant, then ``unsigned'' will be
|
|
|
164 |
* used.
|
|
|
165 |
*
|
|
|
166 |
* PO_CHAR_BIT
|
|
|
167 |
*
|
|
|
168 |
* This should be defined to be the number of bits in a ``char'' object, used
|
|
|
169 |
* to define ``CHAR_BIT''. In an ANSI C compliant standard library, this
|
|
|
170 |
* macro is defined in <limits.h>. If the standard library is not ANSI
|
|
|
171 |
* compliant and no value is provided, then ``8'' will be used.
|
|
|
172 |
*
|
|
|
173 |
* PO_EXIT_SUCCESS
|
|
|
174 |
* PO_EXIT_FAILURE
|
|
|
175 |
*
|
|
|
176 |
* These two macros should be defined to be the values for ``EXIT_SUCCESS''
|
|
|
177 |
* and ``EXIT_FAILUE''. In an ANSI C compliant standard library, they are
|
|
|
178 |
* defined in <stdlib.h>. If the standard library is not ANSI compliant and
|
|
|
179 |
* no value is provided, then ``0'' and ``1'' will be used.
|
|
|
180 |
*
|
|
|
181 |
* PO_UINT_MAX
|
|
|
182 |
*
|
|
|
183 |
* This should be defined to be the maximum unsinged integer, and is used to
|
|
|
184 |
* define ``UINT_MAX''. In an ANSI C compliant standard library, this macro
|
|
|
185 |
* is defined in <limits.h>. If the standard library is not ANSI compliant and
|
|
|
186 |
* no value is provided, then ``(~(unsigned) 0)'' will be used.
|
|
|
187 |
*
|
|
|
188 |
* PO_SEEK_SET
|
|
|
189 |
* PO_SEEK_CUR
|
|
|
190 |
* PO_SEEK_END
|
|
|
191 |
*
|
|
|
192 |
* These should be defined to be the values for ``SEEK_SET'', ``SEEK_CUR'' and
|
|
|
193 |
* ``SEEK_END''. In an ANSI C compliant standard library, they are defined in
|
|
|
194 |
* <stdio.h>. If the standard library is not ANSI compliant and no value is
|
|
|
195 |
* provided, then ``0'', ``1'' and ``2'' will be used.
|
|
|
196 |
*
|
|
|
197 |
* This file also requires that one external function be provided:
|
|
|
198 |
*
|
|
|
199 |
* void E_assertion_failed
|
6 |
7u83 |
200 |
* (CStringP, CStringP, unsigned)
|
2 |
7u83 |
201 |
*
|
|
|
202 |
* This function will be called if an assertion fails. It will be called with
|
|
|
203 |
* the text of the assertion, the name of the file in which the assertion was
|
|
|
204 |
* written, and line on which it occured.
|
|
|
205 |
*
|
|
|
206 |
***=== FROM ANSI ============================================================
|
|
|
207 |
*
|
|
|
208 |
* The following ANSI C functions are declared:
|
|
|
209 |
*
|
|
|
210 |
* NoReturnT abort
|
6 |
7u83 |
211 |
* (void)
|
2 |
7u83 |
212 |
* GenericP calloc
|
6 |
7u83 |
213 |
* (SizeT length, SizeT size)
|
2 |
7u83 |
214 |
* GenericP malloc
|
6 |
7u83 |
215 |
* ((SizeT size)
|
2 |
7u83 |
216 |
* NoReturnT exit
|
6 |
7u83 |
217 |
* (int exit_code)
|
2 |
7u83 |
218 |
* void free
|
6 |
7u83 |
219 |
* (GenericP pointer)
|
2 |
7u83 |
220 |
* CStringP getenv
|
6 |
7u83 |
221 |
* (CStringP name)
|
2 |
7u83 |
222 |
* int memcmp
|
6 |
7u83 |
223 |
* (GenericP ptr1, GenericP ptr2, SizeT length)
|
2 |
7u83 |
224 |
* GenericP memcpy
|
6 |
7u83 |
225 |
* (GenericP to, GenericP from, SizeT length)
|
2 |
7u83 |
226 |
* GenericP memset
|
6 |
7u83 |
227 |
* (GenericP ptr, int val, SizeT length)
|
2 |
7u83 |
228 |
* GenericP memchr
|
6 |
7u83 |
229 |
* (GenericP ptr, int val, SizeT length)
|
2 |
7u83 |
230 |
* SizeT strlen
|
6 |
7u83 |
231 |
* (CStringP string)
|
2 |
7u83 |
232 |
* int strcmp
|
6 |
7u83 |
233 |
* (CStringP string1, CStringP string2)
|
2 |
7u83 |
234 |
* CStringP strcpy
|
6 |
7u83 |
235 |
* (CStringP to, CStringP from)
|
2 |
7u83 |
236 |
* CStringP strchr
|
6 |
7u83 |
237 |
* (CStringP string, int c)
|
2 |
7u83 |
238 |
* CStringP strrchr
|
6 |
7u83 |
239 |
* (CStringP string, int c)
|
2 |
7u83 |
240 |
*
|
|
|
241 |
* Also everything in <setjmp.h> and <stdio.h> is included (hopefully this is
|
|
|
242 |
* sufficiently common to be used even on non-ANSI platforms). Where features
|
|
|
243 |
* are absent on non-ANSI systems, support for them will need to be added.
|
|
|
244 |
*
|
|
|
245 |
***=== FUNCTIONS ============================================================
|
|
|
246 |
*
|
|
|
247 |
** Function: int mkdir
|
6 |
7u83 |
248 |
* (CStringP path, int mode)
|
2 |
7u83 |
249 |
** Exceptions:
|
|
|
250 |
*
|
|
|
251 |
* This function is only declared if the ``FS_MKDIR'' macro is defined. This
|
|
|
252 |
* macro should also be tested before the function is used anywhere. It is
|
|
|
253 |
* the POSIX directory creation function.
|
|
|
254 |
*
|
|
|
255 |
** Function: CStringP strerror
|
6 |
7u83 |
256 |
* (int error)
|
2 |
7u83 |
257 |
** Exceptions:
|
|
|
258 |
*
|
|
|
259 |
* This function is only declared if the ``FS_STRERROR'' macro is defined.
|
|
|
260 |
* This macro should also be tested before the function is used anywhere. It
|
|
|
261 |
* is the ANSI function for obtaining a textual description of a system error
|
|
|
262 |
* message.
|
|
|
263 |
*
|
|
|
264 |
***=== VARIABLES ============================================================
|
|
|
265 |
*
|
|
|
266 |
** Variable: int sys_nerr
|
|
|
267 |
*
|
|
|
268 |
* This variable is only declared if the ``FS_SYS_ERRLIST'' macro is defined.
|
|
|
269 |
* It contains the number of error messages stored in the ``sys_errlist''
|
|
|
270 |
* vector.
|
|
|
271 |
*
|
|
|
272 |
** Variable: CStringP sys_errlist []
|
|
|
273 |
*
|
|
|
274 |
* This variable is only declared if the ``FS_SYS_ERRLIST'' macro is defined.
|
|
|
275 |
* It contains the text of the system error messages.
|
|
|
276 |
*
|
|
|
277 |
** Variable: int errno
|
|
|
278 |
*
|
|
|
279 |
* This variable contains the number of the current system error.
|
|
|
280 |
*
|
|
|
281 |
***=== TYPES ================================================================
|
|
|
282 |
*
|
|
|
283 |
** Type: GenericP
|
|
|
284 |
** Repr: void *
|
|
|
285 |
*
|
|
|
286 |
* This is the generic pointer type. It can be used to store a pointer to any
|
|
|
287 |
* non-function object.
|
|
|
288 |
*
|
|
|
289 |
** Type: NoReturnT
|
|
|
290 |
** Repr: void
|
|
|
291 |
*
|
|
|
292 |
* This is the return type of a function that doesn't return (e.g.
|
|
|
293 |
* ``longjmp''). Normally this is just ``void'', however the GNU C compiler
|
|
|
294 |
* can produce better code if this is declared as ``__volatile__ void''. The
|
|
|
295 |
* TenDRA compiler can be told that a function doesn't return as well.
|
|
|
296 |
*
|
|
|
297 |
** Type: SizeT
|
|
|
298 |
** Type: SizeP
|
|
|
299 |
** Repr: size_t
|
|
|
300 |
*
|
|
|
301 |
* This is the type of the return value of the "sizeof" operator.
|
|
|
302 |
*
|
|
|
303 |
** Type: CStringP
|
|
|
304 |
** Repr: char *
|
|
|
305 |
*
|
|
|
306 |
* This is the C string type. It is defined here to avoid a circularity in
|
|
|
307 |
* the "os-interface" directory. Other directories should access it via the
|
|
|
308 |
* "cstring.h" file.
|
|
|
309 |
*
|
|
|
310 |
** Type: ByteT
|
|
|
311 |
** Type: ByteP
|
|
|
312 |
** Repr: unsigned char
|
|
|
313 |
*
|
|
|
314 |
* This is the byte type. It is possible that this could be larger than a
|
|
|
315 |
* byte in some implementations.
|
|
|
316 |
*
|
|
|
317 |
** Type: BoolT
|
|
|
318 |
** Type: BoolP
|
|
|
319 |
** Repr: int
|
|
|
320 |
*
|
|
|
321 |
* This is the boolean type.
|
|
|
322 |
*
|
|
|
323 |
** Type: CmpT
|
|
|
324 |
** Type: CmpP
|
|
|
325 |
** Repr: enum {CMP_LT, CMP_EQ, CMP_GT}
|
|
|
326 |
*
|
|
|
327 |
* This is the type returned by comparison functions. The values represent
|
|
|
328 |
* the fact that the first argument is less than, equal to, or greater than
|
|
|
329 |
* the second argument respectively.
|
|
|
330 |
*
|
|
|
331 |
***=== CONSTANTS ============================================================
|
|
|
332 |
*
|
|
|
333 |
** Constant: TRUE
|
|
|
334 |
** Constant: FALSE
|
|
|
335 |
*
|
|
|
336 |
* These expand to values suitable for the boolean constants true and false.
|
|
|
337 |
*
|
|
|
338 |
** Constant: EXIT_SUCCESS
|
|
|
339 |
** Constant: EXIT_FAILURE
|
|
|
340 |
*
|
|
|
341 |
* These values should be used as arguments to the ``exit'' function to
|
|
|
342 |
* indicate success or failure of the program.
|
|
|
343 |
*
|
|
|
344 |
** Constant: UINT_MAX
|
|
|
345 |
*
|
|
|
346 |
* This is the maximum unsigned integer value.
|
|
|
347 |
*
|
|
|
348 |
** Constant: CHAR_BIT
|
|
|
349 |
*
|
|
|
350 |
* This is the number of bits in a ``char'' object.
|
|
|
351 |
*
|
|
|
352 |
***=== MACROS ===============================================================
|
|
|
353 |
*
|
|
|
354 |
** Macro: FS_NO_FILE_INFO
|
|
|
355 |
** Exceptions:
|
|
|
356 |
*
|
|
|
357 |
* This macro is defined if ``__FILE__'' or ``__LINE__'' are unsupported.
|
|
|
358 |
* They will be defined as macros with some default value in this case, but
|
|
|
359 |
* the programmer may wish to do something different.
|
|
|
360 |
*
|
|
|
361 |
** Macro: FS_STDC_HASH
|
|
|
362 |
** Exceptions:
|
|
|
363 |
*
|
|
|
364 |
* This macro is defined if the ANSI C hash operators (``#'' and ``##'') are
|
|
|
365 |
* available.
|
|
|
366 |
*
|
|
|
367 |
** Macro: FS_ENUM
|
|
|
368 |
** Macro: FS_NO_ENUM
|
|
|
369 |
** Exceptions:
|
|
|
370 |
*
|
|
|
371 |
* The first of these macros is defined if the compiler supports enumeration
|
|
|
372 |
* types. The second is defined when the first is undefined (and vice-versa).
|
|
|
373 |
* Either can (and should) be tested when enumeration types are being defined,
|
|
|
374 |
* with integer types and macros being used if enumeration types are not
|
|
|
375 |
* supported.
|
|
|
376 |
*
|
|
|
377 |
** Macro: FS_BINARY_STDIO
|
|
|
378 |
** Exceptions:
|
|
|
379 |
*
|
|
|
380 |
* This macro is defined if ANSI binary input and output is supported
|
|
|
381 |
* (i.e. the "b" modifier is allowed in the second argument to ``fopen'').
|
|
|
382 |
*
|
|
|
383 |
** Macro: FS_STRERROR
|
|
|
384 |
** Exceptions:
|
|
|
385 |
*
|
|
|
386 |
* This macro is defined if the ANSI function ``strerror'' is defined.
|
|
|
387 |
*
|
|
|
388 |
** Macro: FS_SYS_ERRLIST
|
|
|
389 |
** Exceptions:
|
|
|
390 |
*
|
|
|
391 |
* This macro is defined if the BSD ``sys_nerr'' and ``sys_errlist'' variables
|
|
|
392 |
* are defined. If ``FS_STRERROR'' is defined, then the ``strerror'' function
|
|
|
393 |
* should be used in preference to ``sys_nerr'' and ``sys_errlist''.
|
|
|
394 |
*
|
|
|
395 |
** Macro: FS_MKDIR
|
|
|
396 |
** Exceptions:
|
|
|
397 |
*
|
|
|
398 |
* This macro is defined if the POSIX function ``mkdir'' is defined.
|
|
|
399 |
*
|
|
|
400 |
** Macro: NIL(type)
|
|
|
401 |
** Exceptions:
|
|
|
402 |
*
|
|
|
403 |
* This is the null pointer macro. The argument is the type for which a null
|
|
|
404 |
* pointer is required.
|
|
|
405 |
*
|
|
|
406 |
** Macro: UNION
|
|
|
407 |
** Exceptions:
|
|
|
408 |
*
|
|
|
409 |
* This macro should be used to define union types that need initialisation.
|
|
|
410 |
* If union initialisation is supported, it expands to ``union'', otherwise it
|
|
|
411 |
* expands to ``struct''.
|
|
|
412 |
*
|
|
|
413 |
** Macro: UB
|
|
|
414 |
** Macro: UE
|
|
|
415 |
** Exceptions:
|
|
|
416 |
*
|
|
|
417 |
* These macros should be used to initialise instances of union types that
|
|
|
418 |
* need initialisation. The ``UB'' macro should go before the initialiser,
|
|
|
419 |
* and the ``UE'' macro should go after it.
|
|
|
420 |
*
|
|
|
421 |
** Macro: INLINE
|
|
|
422 |
** Exceptions:
|
|
|
423 |
*
|
|
|
424 |
* This macro may be used before a function to indicate that the function
|
|
|
425 |
* should be inlined. Normally it expands to nothing, however under the GNU C
|
|
|
426 |
* compiler it expands to ``__inline__'' which causes the compiler to inline
|
|
|
427 |
* the function.
|
|
|
428 |
*
|
|
|
429 |
** Macro: ASSERT (assertion)
|
|
|
430 |
** Exceptions:
|
|
|
431 |
*
|
|
|
432 |
* This macro causes the program to abort if the assertion provided does not
|
|
|
433 |
* hold. Assertion checking is disabled if the ``FS_FAST'' macro is defined
|
|
|
434 |
* or if the ``FS_NO_ASSERT'' macro is defined. The assertion "ASSERT
|
|
|
435 |
* (FALSE);" is used to indicate that the program should never reach the
|
|
|
436 |
* current line.
|
|
|
437 |
*
|
|
|
438 |
** Macro: UNUSED (variable)
|
|
|
439 |
** Exceptions:
|
|
|
440 |
*
|
|
|
441 |
* This macro documents the fact that the specified variable will no longer be
|
|
|
442 |
* used. One use is to indicate function parameters that are not used. On
|
|
|
443 |
* most compilers it will do nothing, but on compilers that support it it will
|
|
|
444 |
* tell the compiler that the variable is not expected to be used.
|
|
|
445 |
*
|
|
|
446 |
** Macro: EXHAUSTIVE
|
|
|
447 |
** Exceptions:
|
|
|
448 |
*
|
|
|
449 |
* This macro documents the fact that the switch statement in which it appears
|
|
|
450 |
* is meant to be exhaustive. It is used as follows:
|
|
|
451 |
*
|
|
|
452 |
* switch (expression) EXHAUSTIVE { ... }
|
|
|
453 |
*
|
|
|
454 |
** Macro: UNREACHED
|
|
|
455 |
** Exceptions:
|
|
|
456 |
*
|
|
|
457 |
* This macro documents the fact that the location that it occurs in should be
|
|
|
458 |
* unreachable.
|
|
|
459 |
*
|
|
|
460 |
** Macro: FALL_THROUGH
|
|
|
461 |
** Exceptions:
|
|
|
462 |
*
|
|
|
463 |
* This macro documents the fact that the current case of a switch statement
|
|
|
464 |
* should follow through into the next (immediately following) case. It is
|
|
|
465 |
* used as follows:
|
|
|
466 |
*
|
|
|
467 |
* case 1:
|
|
|
468 |
* ...
|
|
|
469 |
* FALL_THROUGH;
|
|
|
470 |
* case 2:
|
|
|
471 |
* ...
|
|
|
472 |
*
|
|
|
473 |
**** Change Log:
|
|
|
474 |
* $Log: os-interface.h,v $
|
|
|
475 |
* Revision 1.3 1998/03/16 11:26:35 release
|
|
|
476 |
* Modifications prior to version 4.1.2.
|
|
|
477 |
*
|
|
|
478 |
* Revision 1.2 1998/02/04 10:46:57 release
|
|
|
479 |
* Changes during testing.
|
|
|
480 |
*
|
|
|
481 |
* Revision 1.1.1.1 1998/01/17 15:57:45 release
|
|
|
482 |
* First version to be checked into rolling release.
|
|
|
483 |
*
|
|
|
484 |
* Revision 1.3 1995/09/08 16:11:39 smf
|
|
|
485 |
* Put braces into union initialisation macros (as per ANSI spec).
|
|
|
486 |
* Guarded "gcc" builtin functions.
|
|
|
487 |
*
|
|
|
488 |
* Revision 1.2 1994/12/12 11:45:45 smf
|
|
|
489 |
* Performing changes for 'CR94_178.sid+tld-update' - bringing in line with
|
|
|
490 |
* OSSG C Coding Standards.
|
|
|
491 |
*
|
|
|
492 |
* Revision 1.1.1.1 1994/07/25 16:06:11 smf
|
|
|
493 |
* Initial import of os-interface shared files.
|
|
|
494 |
*
|
|
|
495 |
**/
|
|
|
496 |
|
|
|
497 |
/****************************************************************************/
|
|
|
498 |
|
|
|
499 |
#ifndef H_OS_INTERFACE
|
|
|
500 |
#define H_OS_INTERFACE
|
|
|
501 |
|
|
|
502 |
# ifdef FS_NO_SHORTNAMES
|
|
|
503 |
# undef FS_SHORTNAMES
|
|
|
504 |
# endif /* defined (FS_NO_SHORTNAMES) */
|
|
|
505 |
# ifdef FS_NO_FAST
|
|
|
506 |
# undef FS_FAST
|
|
|
507 |
# endif /* defined (FS_NO_FAST) */
|
|
|
508 |
# ifdef FS_SHORTNAMES
|
|
|
509 |
# include "shortnames.h"
|
|
|
510 |
# ifdef FS_FAST
|
|
|
511 |
# include "fast-short.h"
|
|
|
512 |
# undef FS_FAST
|
|
|
513 |
# endif /* defined (FS_FAST) */
|
|
|
514 |
# endif /* defined (FS_SHORTNAMES) */
|
|
|
515 |
# ifndef FS_FAST
|
|
|
516 |
# define FS_ASSERT
|
|
|
517 |
# endif /* !defined (FS_FAST) */
|
|
|
518 |
# ifdef FS_NO_ASSERT
|
|
|
519 |
# undef FS_ASSERT
|
|
|
520 |
# endif /* defined (FS_NO_ASSERT) */
|
|
|
521 |
|
|
|
522 |
# ifndef FS_NO_STDC
|
|
|
523 |
# ifdef __STDC__
|
|
|
524 |
# define FS_STDC_HASH
|
|
|
525 |
# define FS_PROTOTYPES
|
|
|
526 |
# define FS_VOID_PTR
|
|
|
527 |
# define FS_VOLATILE
|
|
|
528 |
# define FS_CONST
|
|
|
529 |
# define FS_UNION_INIT
|
|
|
530 |
# define FS_ENUM
|
|
|
531 |
# if __STDC__ == 1
|
|
|
532 |
# define FS_ANSI_ENVIRON
|
|
|
533 |
# endif /* __STDC__ == 1 */
|
|
|
534 |
# endif /* defined (__STDC__) */
|
|
|
535 |
# endif /* !defined (FS_NO_STDC) */
|
|
|
536 |
|
|
|
537 |
# ifdef FS_NO_FILE_INFO
|
|
|
538 |
# define __FILE__ "unknown"
|
|
|
539 |
# define __LINE__ 0
|
|
|
540 |
# endif /* defined (FS_NO_FILE_INFO) */
|
|
|
541 |
|
|
|
542 |
# ifdef FS_NO_STDC_HASH
|
|
|
543 |
# undef FS_STDC_HASH
|
|
|
544 |
# endif /* defined (FS_NO_STDC_HASH) */
|
|
|
545 |
|
|
|
546 |
# ifdef FS_NO_VOID_PTR
|
|
|
547 |
# undef FS_VOID_PTR
|
|
|
548 |
# endif /* defined (FS_NO_VOID_PTR) */
|
|
|
549 |
# ifdef FS_VOID_PTR
|
|
|
550 |
typedef void *GenericP;
|
|
|
551 |
# else
|
|
|
552 |
typedef char *GenericP;
|
|
|
553 |
# endif /* defined (FS_VOID_PTR) */
|
|
|
554 |
|
|
|
555 |
# ifdef FS_NO_VOLATILE
|
|
|
556 |
# undef FS_VOLATILE
|
|
|
557 |
# endif /* defined (FS_NO_VOLATILE) */
|
|
|
558 |
# ifndef FS_VOLATILE
|
|
|
559 |
# define volatile
|
|
|
560 |
# endif /* !defined (FS_VOLATILE) */
|
|
|
561 |
|
|
|
562 |
# ifdef FS_NO_CONST
|
|
|
563 |
# undef FS_CONST
|
|
|
564 |
# endif /* defined (FS_NO_CONST) */
|
|
|
565 |
# ifndef FS_CONST
|
|
|
566 |
# define const
|
|
|
567 |
# endif /* !defined (FS_CONST) */
|
|
|
568 |
|
|
|
569 |
# ifdef FS_NO_UNION_INIT
|
|
|
570 |
# undef FS_UNION_INIT
|
|
|
571 |
# endif /* defined (FS_NO_UNION_INIT) */
|
|
|
572 |
# ifdef FS_UNION_INIT
|
|
|
573 |
# define UNION union
|
|
|
574 |
# define UB {
|
|
|
575 |
# define UE }
|
|
|
576 |
# else
|
|
|
577 |
# define UNION struct
|
|
|
578 |
# define UB {
|
|
|
579 |
# define UE }
|
|
|
580 |
# endif /* defined (FS_UNION_INIT) */
|
|
|
581 |
|
|
|
582 |
# ifdef FS_NO_ENUM
|
|
|
583 |
# undef FS_ENUM
|
|
|
584 |
# endif /* defined (FS_NO_ENUM) */
|
|
|
585 |
# ifndef FS_ENUM
|
|
|
586 |
# ifndef FS_NO_ENUM
|
|
|
587 |
# define FS_NO_ENUM
|
|
|
588 |
# endif /* !defined (FS_NO_ENUM) */
|
|
|
589 |
# endif /* !defined (FS_ENUM) */
|
|
|
590 |
|
|
|
591 |
# ifdef FS_NO_ANSI_ENVIRON
|
|
|
592 |
# undef FS_ANSI_ENVIRON
|
|
|
593 |
# endif /* defined (FS_NO_ANSI_ENVIRON) */
|
|
|
594 |
|
|
|
595 |
# ifdef FS_ANSI_ENVIRON
|
|
|
596 |
# define FS_BINARY_STDIO
|
|
|
597 |
# define FS_STRERROR
|
|
|
598 |
# endif /* defined (FS_ANSI_ENVIRON) */
|
|
|
599 |
# ifdef FS_NO_BINARY_STDIO
|
|
|
600 |
# undef FS_BINARY_STDIO
|
|
|
601 |
# endif /* defined (FS_NO_BINARY_STDIO) */
|
|
|
602 |
# ifdef FS_NO_STRERROR
|
|
|
603 |
# undef FS_STRERROR
|
|
|
604 |
# endif /* defined (FS_NO_STRERROR) */
|
|
|
605 |
# ifdef FS_NO_SYS_ERRLIST
|
|
|
606 |
# undef FS_SYS_ERRLIST
|
|
|
607 |
# endif /* defined (FS_NO_SYS_ERRLIST) */
|
|
|
608 |
# ifdef FS_NO_MKDIR
|
|
|
609 |
# undef FS_MKDIR
|
|
|
610 |
# endif /* defined (FS_NO_MKDIR) */
|
|
|
611 |
|
|
|
612 |
# ifdef __GNUC__
|
6 |
7u83 |
613 |
typedef void NoReturnT;
|
2 |
7u83 |
614 |
# else
|
|
|
615 |
# ifdef __TenDRA__
|
|
|
616 |
# pragma TenDRA type NoReturnT for bottom
|
|
|
617 |
# else
|
|
|
618 |
# define NoReturnT void
|
|
|
619 |
# endif /* defined (__TenDRA__) */
|
|
|
620 |
# endif /* defined (__GNUC__) */
|
|
|
621 |
|
|
|
622 |
# ifdef __TenDRA__
|
|
|
623 |
# pragma TenDRA keyword UNUSED for discard variable
|
|
|
624 |
# else
|
|
|
625 |
# define UNUSED(v)
|
|
|
626 |
# endif /* defined (__TenDRA__) */
|
|
|
627 |
|
|
|
628 |
typedef char *CStringP;
|
|
|
629 |
typedef unsigned char ByteT, *ByteP;
|
|
|
630 |
typedef int BoolT, *BoolP;
|
|
|
631 |
# ifdef FS_NO_ENUM
|
|
|
632 |
typedef int CmpT, *CmpP;
|
|
|
633 |
# define CMP_LT (0)
|
|
|
634 |
# define CMP_EQ (1)
|
|
|
635 |
# define CMP_GT (2)
|
|
|
636 |
# else
|
|
|
637 |
typedef enum {
|
|
|
638 |
CMP_LT,
|
|
|
639 |
CMP_EQ,
|
|
|
640 |
CMP_GT
|
|
|
641 |
} CmpT, *CmpP;
|
|
|
642 |
# endif /* defined (FS_NO_ENUM) */
|
|
|
643 |
|
|
|
644 |
# define NIL(type) ((type) (0))
|
|
|
645 |
|
|
|
646 |
# define FALSE (0)
|
|
|
647 |
# define TRUE (1)
|
|
|
648 |
|
|
|
649 |
# ifdef __GNUC__
|
|
|
650 |
# define INLINE __inline__
|
|
|
651 |
# else
|
|
|
652 |
# define INLINE
|
|
|
653 |
# endif /* defined (__GNUC__) */
|
|
|
654 |
|
|
|
655 |
# ifdef FS_MKDIR
|
6 |
7u83 |
656 |
extern int mkdir(CStringP, int);
|
2 |
7u83 |
657 |
# endif /* defined (FS_MKDIR) */
|
|
|
658 |
|
|
|
659 |
# ifdef FS_ASSERT
|
6 |
7u83 |
660 |
extern void E_assertion_failed(CStringP, CStringP, unsigned);
|
2 |
7u83 |
661 |
# ifdef FS_STDC_HASH
|
|
|
662 |
# define ASSERT(a) \
|
|
|
663 |
if (!(a)) { \
|
|
|
664 |
E_assertion_failed (#a, __FILE__, (unsigned) __LINE__); \
|
|
|
665 |
abort (); \
|
|
|
666 |
}
|
|
|
667 |
# else
|
|
|
668 |
# define ASSERT(a) \
|
|
|
669 |
if (!(a)) { \
|
|
|
670 |
E_assertion_failed ("<unavailable>", __FILE__, (unsigned) __LINE__); \
|
|
|
671 |
abort (); \
|
|
|
672 |
}
|
|
|
673 |
# endif /* defined (FS_STDC_HASH) */
|
|
|
674 |
# else
|
|
|
675 |
# define ASSERT(a)
|
|
|
676 |
# endif /* defined (FS_ASSERT) */
|
|
|
677 |
|
|
|
678 |
# ifdef __TenDRA__
|
|
|
679 |
# pragma TenDRA keyword EXHAUSTIVE for exhaustive
|
|
|
680 |
# pragma TenDRA keyword FALL_THROUGH for fall into case
|
|
|
681 |
# pragma TenDRA keyword UNREACHED for set unreachable
|
|
|
682 |
# else
|
|
|
683 |
# define EXHAUSTIVE
|
|
|
684 |
# define FALL_THROUGH
|
|
|
685 |
# define UNREACHED ASSERT (FALSE)
|
|
|
686 |
# endif /* defined (__TenDRA__) */
|
|
|
687 |
|
|
|
688 |
# ifdef FS_ANSI_ENVIRON
|
|
|
689 |
# include <errno.h>
|
|
|
690 |
# include <limits.h>
|
|
|
691 |
# include <setjmp.h>
|
|
|
692 |
# include <stddef.h>
|
|
|
693 |
# include <stdio.h>
|
|
|
694 |
# include <stdlib.h>
|
|
|
695 |
# include <string.h>
|
|
|
696 |
typedef size_t SizeT, *SizeP;
|
|
|
697 |
# else
|
|
|
698 |
|
|
|
699 |
# ifdef PO_SIZE_T_TYPE
|
|
|
700 |
typedef PO_SIZE_T_TYPE SizeT, *SizeP;
|
|
|
701 |
# else
|
|
|
702 |
typedef unsigned SizeT, *SizeP;
|
|
|
703 |
# endif /* defined (PO_SIZE_T_TYPE) */
|
|
|
704 |
|
6 |
7u83 |
705 |
extern NoReturnT abort(void);
|
|
|
706 |
extern GenericP calloc(SizeT, SizeT);
|
|
|
707 |
extern GenericP malloc(SizeT);
|
|
|
708 |
extern NoReturnT exit(int);
|
|
|
709 |
extern void free(GenericP);
|
|
|
710 |
extern CStringP getenv(CStringP);
|
2 |
7u83 |
711 |
# ifndef __GNUC__
|
6 |
7u83 |
712 |
extern int memcmp(GenericP, GenericP, SizeT);
|
2 |
7u83 |
713 |
# endif /* defined (__GNUC__) */
|
|
|
714 |
# ifndef __GNUC__
|
6 |
7u83 |
715 |
extern GenericP memcpy(GenericP, GenericP, SizeT);
|
2 |
7u83 |
716 |
# endif /* defined (__GNUC__) */
|
6 |
7u83 |
717 |
extern GenericP memset(GenericP, int, SizeT);
|
|
|
718 |
extern GenericP memchr(GenericP, int, SizeT);
|
2 |
7u83 |
719 |
# ifndef __GNUC__
|
6 |
7u83 |
720 |
extern SizeT strlen(CStringP);
|
2 |
7u83 |
721 |
# endif /* defined (__GNUC__) */
|
|
|
722 |
# ifndef __GNUC__
|
6 |
7u83 |
723 |
extern int strcmp(CStringP, CStringP);
|
2 |
7u83 |
724 |
# endif /* defined (__GNUC__) */
|
|
|
725 |
# ifndef __GNUC__
|
6 |
7u83 |
726 |
extern int strncmp(CStringP, CStringP, SizeT);
|
2 |
7u83 |
727 |
# endif /* defined (__GNUC__) */
|
|
|
728 |
# ifndef __GNUC__
|
6 |
7u83 |
729 |
extern CStringP strcpy(CStringP, CStringP);
|
2 |
7u83 |
730 |
# endif /* defined (__GNUC__) */
|
6 |
7u83 |
731 |
extern CStringP strchr(CStringP, int);
|
|
|
732 |
extern CStringP strrchr(CStringP, int);
|
|
|
733 |
extern int errno;
|
2 |
7u83 |
734 |
# ifdef FS_STRERROR
|
6 |
7u83 |
735 |
extern CStringP strerror(int);
|
2 |
7u83 |
736 |
# endif /* defined (FS_STRERROR) */
|
|
|
737 |
|
|
|
738 |
# include <setjmp.h>
|
|
|
739 |
# include <stdio.h>
|
|
|
740 |
|
|
|
741 |
# endif /* !defined (FS_ANSI_ENVIRON) */
|
|
|
742 |
|
|
|
743 |
# ifndef CHAR_BIT
|
|
|
744 |
# ifdef PO_CHAR_BIT
|
|
|
745 |
# define CHAR_BIT PO_CHAR_BIT
|
|
|
746 |
# else
|
|
|
747 |
# define CHAR_BIT 8
|
|
|
748 |
# endif /* defined (PO_CHAR_BIT) */
|
|
|
749 |
# endif /* !defined (CHAR_BIT) */
|
|
|
750 |
|
|
|
751 |
# ifndef EXIT_SUCCESS
|
|
|
752 |
# ifdef PO_EXIT_SUCCESS
|
|
|
753 |
# define EXIT_SUCCESS PO_EXIT_SUCCESS
|
|
|
754 |
# else
|
|
|
755 |
# define EXIT_SUCCESS (0)
|
|
|
756 |
# endif /* defined (PO_EXIT_SUCCESS) */
|
|
|
757 |
# endif /* !defined (EXIT_SUCCESS) */
|
|
|
758 |
|
|
|
759 |
# ifndef EXIT_FAILURE
|
|
|
760 |
# ifdef PO_EXIT_FAILURE
|
|
|
761 |
# define EXIT_FAILURE PO_EXIT_FAILURE
|
|
|
762 |
# else
|
|
|
763 |
# define EXIT_FAILURE (1)
|
|
|
764 |
# endif /* defined (PO_EXIT_FAILURE) */
|
|
|
765 |
# endif /* !defined (EXIT_FAILURE) */
|
|
|
766 |
|
|
|
767 |
# ifndef UINT_MAX
|
|
|
768 |
# ifdef PO_UINT_MAX
|
|
|
769 |
# define UINT_MAX PO_UINT_MAX
|
|
|
770 |
# else
|
|
|
771 |
# define UINT_MAX (~(unsigned) 0)
|
|
|
772 |
# endif /* defined (PO_UINT_MAX) */
|
|
|
773 |
# endif /* !defined (UINT_MAX) */
|
|
|
774 |
|
|
|
775 |
# ifndef SEEK_SET
|
|
|
776 |
# ifdef PO_SEEK_SET
|
|
|
777 |
# define SEEK_SET PO_SEEK_SET
|
|
|
778 |
# else
|
|
|
779 |
# define SEEK_SET (0)
|
|
|
780 |
# endif /* defined (PO_SEEK_SET) */
|
|
|
781 |
# endif /* !defined (SEEK_SET) */
|
|
|
782 |
|
|
|
783 |
# ifndef SEEK_CUR
|
|
|
784 |
# ifdef PO_SEEK_CUR
|
|
|
785 |
# define SEEK_CUR PO_SEEK_CUR
|
|
|
786 |
# else
|
|
|
787 |
# define SEEK_CUR (1)
|
|
|
788 |
# endif /* defined (PO_SEEK_CUR) */
|
|
|
789 |
# endif /* !defined (SEEK_CUR) */
|
|
|
790 |
|
|
|
791 |
# ifndef SEEK_END
|
|
|
792 |
# ifdef PO_SEEK_END
|
|
|
793 |
# define SEEK_END PO_SEEK_END
|
|
|
794 |
# else
|
|
|
795 |
# define SEEK_END (2)
|
|
|
796 |
# endif /* defined (PO_SEEK_END) */
|
|
|
797 |
# endif /* !defined (SEEK_END) */
|
|
|
798 |
|
|
|
799 |
# ifdef FS_SYS_ERRLIST
|
6 |
7u83 |
800 |
extern int sys_nerr;
|
|
|
801 |
extern CStringP sys_errlist[];
|
2 |
7u83 |
802 |
# endif /* defined (FS_SYS_ERRLIST) */
|
|
|
803 |
|
|
|
804 |
#endif /* !defined (H_OS_INTERFACE) */
|