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