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