1 /*	SCCS Id: @(#)system.h	3.4	2001/12/07	*/
2 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
3 /* NetHack may be freely redistributed.  See license for details. */
4 
5 #ifndef SYSTEM_H
6 #define SYSTEM_H
7 
8 #if !defined(__cplusplus) && !defined(__GO32__)
9 
10 #define E extern
11 
12 /* some old <sys/types.h> may not define off_t and size_t; if your system is
13  * one of these, define them by hand below
14  */
15 #if (defined(VMS) && !defined(__GNUC__)) || defined(MAC)
16 #include <types.h>
17 #else
18 # ifndef AMIGA
19 #include <sys/types.h>
20 # endif
21 #endif
22 
23 #if (defined(MICRO) && !defined(TOS)) || defined(ANCIENT_VAXC)
24 # if !defined(_SIZE_T) && !defined(__size_t) /* __size_t for CSet/2 */
25 #  define _SIZE_T
26 #  if !((defined(MSDOS) || defined(OS2)) && defined(_SIZE_T_DEFINED)) /* MSC 5.1 */
27 #   if !(defined(__GNUC__) && defined(AMIGA))
28 typedef unsigned int	size_t;
29 #   endif
30 #  endif
31 # endif
32 #endif	/* MICRO && !TOS */
33 
34 #if defined(__TURBOC__) || defined(MAC)
35 #include <time.h>	/* time_t is not in <sys/types.h> */
36 #endif
37 #if defined(ULTRIX) && !(defined(ULTRIX_PROTO) || defined(NHSTDC))
38 /* The Ultrix v3.0 <sys/types.h> seems to be very wrong. */
39 # define time_t long
40 #endif
41 
42 #if defined(ULTRIX) || defined(VMS)
43 # define off_t long
44 #endif
45 #if defined(AZTEC) || defined(THINKC4) || defined(__TURBOC__)
46 typedef long	off_t;
47 #endif
48 
49 #endif /* !__cplusplus && !__GO32__ */
50 
51 /* You may want to change this to fit your system, as this is almost
52  * impossible to get right automatically.
53  * This is the type of signal handling functions.
54  */
55 #if !defined(OS2) && (defined(_MSC_VER) || defined(__TURBOC__) || defined(__SC__) || defined(WIN32))
56 # define SIG_RET_TYPE void (__cdecl *)(int)
57 #endif
58 #ifndef SIG_RET_TYPE
59 # if defined(NHSTDC) || defined(POSIX_TYPES) || defined(OS2) || defined(__DECC)
60 #  define SIG_RET_TYPE void (*)()
61 # endif
62 #endif
63 #ifndef SIG_RET_TYPE
64 # if defined(ULTRIX) || defined(SUNOS4) || defined(SVR3) || defined(SVR4)
65 	/* SVR3 is defined automatically by some systems */
66 #  define SIG_RET_TYPE void (*)()
67 # endif
68 #endif
69 #ifndef SIG_RET_TYPE	/* BSD, SIII, SVR2 and earlier, Sun3.5 and earlier */
70 # define SIG_RET_TYPE int (*)()
71 #endif
72 
73 #if !defined(__cplusplus) && !defined(__GO32__)
74 
75 #if defined(BSD) || defined(ULTRIX) || defined(RANDOM)
76 # ifdef random
77 # undef random
78 # endif
79 # if !defined(__SC__) && !defined(LINUX)
80 E  long NDECL(random);
81 # endif
82 # if defined(__FreeBSD__)
83 #include <stdlib.h> /* srandom() differs between versions of FreeBSD. */
84 # elif (!defined(SUNOS4) && !defined(bsdi) && !defined(__FreeBSD__)) || defined(RANDOM)
85 E void FDECL(srandom, (unsigned int));
86 # else
87 #  if !defined(bsdi) && !defined(__FreeBSD__)
88 E int FDECL(srandom, (unsigned int));
89 #  endif
90 # endif
91 #else
92 E long lrand48();
93 E void srand48();
94 #endif /* BSD || ULTRIX || RANDOM */
95 
96 #if !defined(BSD) || defined(ultrix)
97 			/* real BSD wants all these to return int */
98 # ifndef MICRO
99 E void FDECL(exit, (int));
100 # endif /* MICRO */
101 /* compensate for some CSet/2 bogosities */
102 # if defined(OS2_CSET2) && defined(OS2_CSET2_VER_2)
103 #  define open	  _open
104 #  define close   _close
105 #  define read	  _read
106 #  define write   _write
107 #  define lseek   _lseek
108 #  define chdir   _chdir
109 #  define getcwd  _getcwd
110 #  define setmode _setmode
111 # endif /* OS2_CSET2 && OS2_CSET2_VER_2 */
112 /* If flex thinks that we're not __STDC__ it declares free() to return
113    int and we die.  We must use __STDC__ instead of NHSTDC because
114    the former is naturally what flex tests for. */
115 # if defined(__STDC__) || !defined(FLEX_SCANNER)
116 #  ifndef OS2_CSET2
117 #   ifndef MONITOR_HEAP
118 E void FDECL(free, (genericptr_t));
119 #   endif
120 #  endif
121 # endif
122 #if !defined(__SASC_60) && !defined(_DCC) && !defined(__SC__)
123 # if defined(AMIGA) && !defined(AZTEC_50) && !defined(__GNUC__)
124 E int FDECL(perror, (const char *));
125 # else
126 #  if !(defined(ULTRIX_PROTO) && defined(__GNUC__))
127 E void FDECL(perror, (const char *));
128 #  endif
129 # endif
130 #endif
131 #endif
132 #ifndef NeXT
133 #ifdef POSIX_TYPES
134 E void FDECL(qsort, (genericptr_t,size_t,size_t,
135 		     int(*)(const genericptr,const genericptr)));
136 #else
137 # if defined(BSD) || defined(ULTRIX)
138 E  int qsort();
139 # else
140 #  if !defined(LATTICE) && !defined(AZTEC_50)
141 E   void FDECL(qsort, (genericptr_t,size_t,size_t,
142 		       int(*)(const genericptr,const genericptr)));
143 #  endif
144 # endif
145 #endif
146 #endif /* NeXT */
147 
148 #ifndef __SASC_60
149 #if !defined(AZTEC_50) && !defined(__GNUC__)
150 /* may already be defined */
151 
152 # ifdef ULTRIX
153 #  ifdef ULTRIX_PROTO
154 E int FDECL(lseek, (int,off_t,int));
155 #  else
156 E long FDECL(lseek, (int,off_t,int));
157 #  endif
158   /* Ultrix 3.0 man page mistakenly says it returns an int. */
159 E int FDECL(write, (int,char *,int));
160 E int FDECL(link, (const char *, const char*));
161 # else
162 # ifndef bsdi
163 E long FDECL(lseek, (int,long,int));
164 # endif
165 #  if defined(POSIX_TYPES) || defined(__TURBOC__)
166 #   ifndef bsdi
167 E int FDECL(write, (int, const void *,unsigned));
168 #   endif
169 #  else
170 #   ifndef __MWERKS__	/* metrowerks defines write via universal headers */
171 E int FDECL(write, (int,genericptr_t,unsigned));
172 #   endif
173 #  endif
174 # endif /* ULTRIX */
175 
176 # ifdef OS2_CSET2	/* IBM CSet/2 */
177 #  ifdef OS2_CSET2_VER_1
178 E int FDECL(unlink, (char *));
179 #  else
180 E int FDECL(unlink, (const char *)); /* prototype is ok in ver >= 2 */
181 #  endif
182 # else
183 #  ifndef __SC__
184 E int FDECL(unlink, (const char *));
185 #  endif
186 # endif
187 
188 #endif /* AZTEC_50 && __GNUC__ */
189 
190 #ifdef MAC
191 #ifndef __CONDITIONALMACROS__	/* universal headers */
192 E int FDECL(close, (int));		/* unistd.h */
193 E int FDECL(read, (int, char *, int));	/* unistd.h */
194 E int FDECL(chdir, (const char *));	/* unistd.h */
195 E char *FDECL(getcwd, (char *,int));	/* unistd.h */
196 #endif
197 
198 E int FDECL(open, (const char *,int));
199 #endif
200 
201 #if defined(MICRO)
202 E int FDECL(close, (int));
203 #ifndef __EMX__
204 E int FDECL(read, (int,genericptr_t,unsigned int));
205 #endif
206 E int FDECL(open, (const char *,int,...));
207 E int FDECL(dup2, (int, int));
208 E int FDECL(setmode, (int,int));
209 E int NDECL(kbhit);
210 # if !defined(_DCC)
211 #  if defined(__TURBOC__)
212 E int FDECL(chdir, (const char *));
213 #  else
214 #   ifndef __EMX__
215 E int FDECL(chdir, (char *));
216 #   endif
217 #  endif
218 #  ifndef __EMX__
219 E char *FDECL(getcwd, (char *,int));
220 #  endif
221 # endif /* !_DCC */
222 #endif
223 
224 #ifdef ULTRIX
225 E int FDECL(close, (int));
226 E int FDECL(atoi, (const char *));
227 E int FDECL(chdir, (const char *));
228 # if !defined(ULTRIX_CC20) && !defined(__GNUC__)
229 E int FDECL(chmod, (const char *,int));
230 E mode_t FDECL(umask, (int));
231 # endif
232 E int FDECL(read, (int,genericptr_t,unsigned));
233 /* these aren't quite right, but this saves including lots of system files */
234 E int FDECL(stty, (int,genericptr_t));
235 E int FDECL(gtty, (int,genericptr_t));
236 E int FDECL(ioctl, (int, int, char*));
237 E int FDECL(isatty, (int));	/* 1==yes, 0==no, -1==error */
238 #include <sys/file.h>
239 # if defined(ULTRIX_PROTO) || defined(__GNUC__)
240 E int NDECL(fork);
241 # else
242 E long NDECL(fork);
243 # endif
244 #endif /* ULTRIX */
245 
246 #ifdef VMS
247 # ifndef abs
248 E int FDECL(abs, (int));
249 # endif
250 E int FDECL(atexit, (void (*)(void)));
251 E int FDECL(atoi, (const char *));
252 E int FDECL(chdir, (const char *));
253 E int FDECL(chown, (const char *,unsigned,unsigned));
254 # ifdef __DECC_VER
255 E int FDECL(chmod, (const char *,mode_t));
256 E mode_t FDECL(umask, (mode_t));
257 # else
258 E int FDECL(chmod, (const char *,int));
259 E int FDECL(umask, (int));
260 # endif
261 /* #include <unixio.h> */
262 E int FDECL(close, (int));
263 E int VDECL(creat, (const char *,unsigned,...));
264 E int FDECL(delete, (const char *));
265 E int FDECL(fstat, ( /*_ int, stat_t * _*/ ));
266 E int FDECL(isatty, (int));	/* 1==yes, 0==no, -1==error */
267 E long FDECL(lseek, (int,long,int));
268 E int VDECL(open, (const char *,int,unsigned,...));
269 E int FDECL(read, (int,genericptr_t,unsigned));
270 E int FDECL(rename, (const char *,const char *));
271 E int FDECL(stat, ( /*_ const char *,stat_t * _*/ ));
272 E int FDECL(write, (int,const genericptr,unsigned));
273 #endif
274 
275 #endif	/* __SASC_60 */
276 
277 /* both old & new versions of Ultrix want these, but real BSD does not */
278 #ifdef ultrix
279 E void abort();
280 E void bcopy();
281 # ifdef ULTRIX
282 E int FDECL(system, (const char *));
283 #  ifndef _UNISTD_H_
284 E int FDECL(execl, (const char *, ...));
285 #  endif
286 # endif
287 #endif
288 #ifdef MICRO
289 E void NDECL(abort);
290 E void FDECL(_exit, (int));
291 E int FDECL(system, (const char *));
292 #endif
293 #if defined(HPUX) && !defined(_POSIX_SOURCE)
294 E long NDECL(fork);
295 #endif
296 
297 #ifdef POSIX_TYPES
298 /* The POSIX string.h is required to define all the mem* and str* functions */
299 #include <string.h>
300 #else
301 #if defined(SYSV) || defined(VMS) || defined(MAC) || defined(SUNOS4)
302 # if defined(NHSTDC) || (defined(VMS) && !defined(ANCIENT_VAXC))
303 #  if !defined(_AIX32) && !(defined(SUNOS4) && defined(__STDC__))
304 				/* Solaris unbundled cc (acc) */
305 E int FDECL(memcmp, (const void *,const void *,size_t));
306 E void *FDECL(memcpy, (void *, const void *, size_t));
307 E void *FDECL(memset, (void *, int, size_t));
308 #  endif
309 # else
310 #  ifndef memcmp	/* some systems seem to macro these back to b*() */
311 E int memcmp();
312 #  endif
313 #  ifndef memcpy
314 E char *memcpy();
315 #  endif
316 #  ifndef memset
317 E char *memset();
318 #  endif
319 # endif
320 #else
321 # ifdef HPUX
322 E int FDECL(memcmp, (char *,char *,int));
323 E void *FDECL(memcpy, (char *,char *,int));
324 E void *FDECL(memset, (char*,int,int));
325 # endif
326 #endif
327 #endif /* POSIX_TYPES */
328 
329 #if defined(MICRO) && !defined(LATTICE)
330 # if defined(TOS) && defined(__GNUC__)
331 E int FDECL(memcmp, (const void *,const void *,size_t));
332 E void *FDECL(memcpy, (void *,const void *,size_t));
333 E void *FDECL(memset, (void *,int,size_t));
334 # else
335 #  if defined(AZTEC_50) || defined(NHSTDC) || defined(WIN32)
336 E int  FDECL(memcmp, (const void *, const void *, size_t));
337 E void *FDECL(memcpy, (void *, const void *, size_t));
338 E void *FDECL(memset, (void *, int, size_t));
339 #  else
340 E int FDECL(memcmp, (char *,char *,unsigned int));
341 E char *FDECL(memcpy, (char *,char *,unsigned int));
342 E char *FDECL(memset, (char*,int,int));
343 #  endif /* AZTEC_50 || NHSTDC */
344 # endif /* TOS */
345 #endif /* MICRO */
346 
347 #if defined(BSD) && defined(ultrix)	/* i.e., old versions of Ultrix */
348 E void sleep();
349 #endif
350 #if defined(ULTRIX) || defined(SYSV)
351 E unsigned sleep();
352 #endif
353 #if defined(HPUX)
354 E unsigned int FDECL(sleep, (unsigned int));
355 #endif
356 #ifdef VMS
357 E int FDECL(sleep, (unsigned));
358 #endif
359 
360 E char *FDECL(getenv, (const char *));
361 E char *getlogin();
362 #if defined(HPUX) && !defined(_POSIX_SOURCE)
363 E long NDECL(getuid);
364 E long NDECL(getgid);
365 E long NDECL(getpid);
366 #else
367 # ifdef POSIX_TYPES
368 E pid_t NDECL(getpid);
369 E uid_t NDECL(getuid);
370 E gid_t NDECL(getgid);
371 #  ifdef VMS
372 E pid_t NDECL(getppid);
373 #  endif
374 # else	/*!POSIX_TYPES*/
375 #  ifndef getpid		/* Borland C defines getpid() as a macro */
376 E int NDECL(getpid);
377 #  endif
378 #  ifdef VMS
379 E int NDECL(getppid);
380 E unsigned NDECL(getuid);
381 E unsigned NDECL(getgid);
382 #  endif
383 #  if defined(ULTRIX) && !defined(_UNISTD_H_)
384 E unsigned NDECL(getuid);
385 E unsigned NDECL(getgid);
386 E int FDECL(setgid, (int));
387 E int FDECL(setuid, (int));
388 #  endif
389 # endif	/*?POSIX_TYPES*/
390 #endif	/*?(HPUX && !_POSIX_SOURCE)*/
391 
392 /* add more architectures as needed */
393 #if defined(HPUX)
394 #define seteuid(x) setreuid(-1, (x));
395 #endif
396 
397 /*# string(s).h #*/
398 #if !defined(_XtIntrinsic_h) && !defined(POSIX_TYPES)
399 /* <X11/Intrinsic.h> #includes <string[s].h>; so does defining POSIX_TYPES */
400 
401 #if (defined(ULTRIX) || defined(NeXT)) && defined(__GNUC__)
402 #include <strings.h>
403 #else
404 E char	*FDECL(strcpy, (char *,const char *));
405 E char	*FDECL(strncpy, (char *,const char *,size_t));
406 E char	*FDECL(strcat, (char *,const char *));
407 E char	*FDECL(strncat, (char *,const char *,size_t));
408 E char	*FDECL(strpbrk, (const char *,const char *));
409 
410 # if defined(SYSV) || defined(MICRO) || defined(MAC) || defined(VMS) || defined(HPUX)
411 E char	*FDECL(strchr, (const char *,int));
412 E char	*FDECL(strrchr, (const char *,int));
413 # else /* BSD */
414 E char	*FDECL(index, (const char *,int));
415 E char	*FDECL(rindex, (const char *,int));
416 # endif
417 
418 E int	FDECL(strcmp, (const char *,const char *));
419 E int	FDECL(strncmp, (const char *,const char *,size_t));
420 # if defined(MICRO) || defined(MAC) || defined(VMS)
421 E size_t FDECL(strlen, (const char *));
422 # else
423 # ifdef HPUX
424 E unsigned int	FDECL(strlen, (char *));
425 #  else
426 #   if !(defined(ULTRIX_PROTO) && defined(__GNUC__))
427 E int	FDECL(strlen, (const char *));
428 #   endif
429 #  endif /* HPUX */
430 # endif /* MICRO */
431 #endif /* ULTRIX */
432 
433 #endif	/* !_XtIntrinsic_h_ && !POSIX_TYPES */
434 
435 #if defined(ULTRIX) && defined(__GNUC__)
436 E char	*FDECL(index, (const char *,int));
437 E char	*FDECL(rindex, (const char *,int));
438 #endif
439 
440 /* Old varieties of BSD have char *sprintf().
441  * Newer varieties of BSD have int sprintf() but allow for the old char *.
442  * Several varieties of SYSV and PC systems also have int sprintf().
443  * If your system doesn't agree with this breakdown, you may want to change
444  * this declaration, especially if your machine treats the types differently.
445  * If your system defines sprintf, et al, in stdio.h, add to the initial
446  * #if.
447  */
448 #if defined(ULTRIX) || defined(__DECC) || defined(__SASC_60) || defined(WIN32)
449 #define SPRINTF_PROTO
450 #endif
451 #if (defined(SUNOS4) && defined(__STDC__)) || defined(_AIX32)
452 #define SPRINTF_PROTO
453 #endif
454 #if defined(TOS) || defined(AZTEC_50) || defined(__sgi) || defined(__GNUC__)
455 	/* problem with prototype mismatches */
456 #define SPRINTF_PROTO
457 #endif
458 #if defined(__MWERKS__) || defined(__SC__)
459 	/* Metrowerks already has a prototype for sprintf() */
460 # define SPRINTF_PROTO
461 #endif
462 
463 #ifndef SPRINTF_PROTO
464 # if defined(POSIX_TYPES) || defined(DGUX) || defined(NeXT) || !defined(BSD)
465 E  int FDECL(sprintf, (char *,const char *,...));
466 # else
467 #  define OLD_SPRINTF
468 E  char *sprintf();
469 # endif
470 #endif
471 #ifdef SPRINTF_PROTO
472 # undef SPRINTF_PROTO
473 #endif
474 
475 #ifndef __SASC_60
476 #ifdef NEED_VARARGS
477 # if defined(USE_STDARG) || defined(USE_VARARGS)
478 #  if !defined(SVR4) && !defined(apollo)
479 #   if !(defined(ULTRIX_PROTO) && defined(__GNUC__))
480 #    if !(defined(SUNOS4) && defined(__STDC__)) /* Solaris unbundled cc (acc) */
481 E int FDECL(vsprintf, (char *, const char *, va_list));
482 E int FDECL(vfprintf, (FILE *, const char *, va_list));
483 E int FDECL(vprintf, (const char *, va_list));
484 #    endif
485 #   endif
486 #  endif
487 # else
488 #  define vprintf	printf
489 #  define vfprintf	fprintf
490 #  define vsprintf	sprintf
491 # endif
492 #endif /* NEED_VARARGS */
493 #endif
494 
495 
496 #ifdef MICRO
497 E int FDECL(tgetent, (const char *,const char *));
498 E void FDECL(tputs, (const char *,int,int (*)()));
499 E int FDECL(tgetnum, (const char *));
500 E int FDECL(tgetflag, (const char *));
501 E char *FDECL(tgetstr, (const char *,char **));
502 E char *FDECL(tgoto, (const char *,int,int));
503 #else
504 # if ! (defined(HPUX) && defined(_POSIX_SOURCE))
505 E int FDECL(tgetent, (char *,const char *));
506 E void FDECL(tputs, (const char *,int,int (*)()));
507 # endif
508 E int FDECL(tgetnum, (const char *));
509 E int FDECL(tgetflag, (const char *));
510 E char *FDECL(tgetstr, (const char *,char **));
511 E char *FDECL(tgoto, (const char *,int,int));
512 #endif
513 
514 #ifdef ALLOC_C
515 E genericptr_t FDECL(malloc, (size_t));
516 #endif
517 
518 /* time functions */
519 
520 # ifndef LATTICE
521 #  if !(defined(ULTRIX_PROTO) && defined(__GNUC__))
522 E struct tm *FDECL(localtime, (const time_t *));
523 #  endif
524 # endif
525 
526 # if defined(ULTRIX) || (defined(BSD) && defined(POSIX_TYPES)) || defined(SYSV) || defined(MICRO) || defined(VMS) || defined(MAC) || (defined(HPUX) && defined(_POSIX_SOURCE))
527 E time_t FDECL(time, (time_t *));
528 # else
529 E long FDECL(time, (time_t *));
530 # endif /* ULTRIX */
531 
532 #ifdef VMS
533 	/* used in makedefs.c, but missing from gcc-vms's <time.h> */
534 E char *FDECL(ctime, (const time_t *));
535 #endif
536 
537 
538 #ifdef MICRO
539 # ifdef abs
540 # undef abs
541 # endif
542 E int FDECL(abs, (int));
543 # ifdef atoi
544 # undef atoi
545 # endif
546 E int FDECL(atoi, (const char *));
547 #endif
548 
549 #undef E
550 
551 #endif /*  !__cplusplus && !__GO32__ */
552 
553 #endif /* SYSTEM_H */
554