system.h

Go to the documentation of this file.
00001 /*      SCCS Id: @(#)system.h   3.4     2001/12/07      */
00002 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
00003 /* NetHack may be freely redistributed.  See license for details. */
00004 
00005 #ifndef SYSTEM_H
00006 #define SYSTEM_H
00007 
00008 #if !defined(__cplusplus) && !defined(__GO32__)
00009 
00010 #define E extern
00011 
00012 #ifdef AUTOCONF
00013 /*
00014  * When using GNU autoconf to configure, the switches are output to
00015  * autoconf.h which should override the defaults set earlier in
00016  * config.h and *conf.h
00017  */
00018 #include "autoconf.h"
00019 #if HAVE_STRING_H
00020 #include <string.h>
00021 #endif
00022 #if HAVE_DECL_STRNICMP && !HAVE_DECL_STRNCMPI
00023 #define strncmpi(a,b,c) strnicmp(a,b,c)
00024 #endif
00025 #endif
00026 
00027 /* some old <sys/types.h> may not define off_t and size_t; if your system is
00028  * one of these, define them by hand below
00029  */
00030 #if (defined(VMS) && !defined(__GNUC__)) || defined(MAC)
00031 #include <types.h>
00032 #else
00033 # ifndef AMIGA
00034 #include <sys/types.h>
00035 # endif
00036 #endif
00037 
00038 #if (defined(MICRO) && !defined(TOS)) || defined(ANCIENT_VAXC)
00039 # if !defined(_SIZE_T) && !defined(__size_t) /* __size_t for CSet/2 */
00040 #  define _SIZE_T
00041 #  if !((defined(MSDOS) || defined(OS2)) && defined(_SIZE_T_DEFINED)) /* MSC 5.1 */
00042 #   if !(defined(__GNUC__) && defined(AMIGA))
00043 typedef unsigned int    size_t;
00044 #   endif
00045 #  endif
00046 # endif
00047 #endif  /* MICRO && !TOS */
00048 
00049 #if defined(__TURBOC__) || defined(MAC)
00050 #include <time.h>       /* time_t is not in <sys/types.h> */
00051 #endif
00052 #if defined(ULTRIX) && !(defined(ULTRIX_PROTO) || defined(NHSTDC))
00053 /* The Ultrix v3.0 <sys/types.h> seems to be very wrong. */
00054 # define time_t long
00055 #endif
00056 
00057 #if defined(ULTRIX) || defined(VMS)
00058 # define off_t long
00059 #endif
00060 #if defined(AZTEC) || defined(THINKC4) || defined(__TURBOC__)
00061 typedef long    off_t;
00062 #endif
00063 
00064 #endif /* !__cplusplus && !__GO32__ */
00065 
00066 /* You may want to change this to fit your system, as this is almost
00067  * impossible to get right automatically.
00068  * This is the type of signal handling functions.
00069  */
00070 #if !defined(OS2) && (defined(_MSC_VER) || defined(__TURBOC__) || defined(__SC__) || defined(WIN32))
00071 # define SIG_RET_TYPE void (__cdecl *)(int)
00072 #endif
00073 #ifndef SIG_RET_TYPE
00074 # if defined(NHSTDC) || defined(POSIX_TYPES) || defined(OS2) || defined(__DECC)
00075 #  define SIG_RET_TYPE void (*)()
00076 # endif
00077 #endif
00078 #ifndef SIG_RET_TYPE
00079 # if defined(ULTRIX) || defined(SUNOS4) || defined(SVR3) || defined(SVR4)
00080         /* SVR3 is defined automatically by some systems */
00081 #  define SIG_RET_TYPE void (*)()
00082 # endif
00083 #endif
00084 #ifndef SIG_RET_TYPE    /* BSD, SIII, SVR2 and earlier, Sun3.5 and earlier */
00085 # define SIG_RET_TYPE int (*)()
00086 #endif
00087 
00088 #if !defined(__cplusplus) && !defined(__GO32__)
00089 
00090 #if defined(BSD) || defined(ULTRIX) || defined(RANDOM)
00091 # ifdef random
00092 # undef random
00093 # endif
00094 # if !defined(__SC__) && !defined(LINUX)
00095 E  long NDECL(random);
00096 # endif
00097 # if (!defined(SUNOS4) && !defined(bsdi) && !defined(__FreeBSD__)) || defined(RANDOM)
00098 E void FDECL(srandom, (unsigned int));
00099 # else
00100 #  if !defined(bsdi) && !defined(__FreeBSD__)
00101 E int FDECL(srandom, (unsigned int));
00102 #  endif
00103 # endif
00104 #else
00105 E long lrand48();
00106 E void srand48();
00107 #endif /* BSD || ULTRIX || RANDOM */
00108 
00109 #ifdef LEGACY_CODE
00110 #if !defined(BSD) || defined(ultrix)
00111                         /* real BSD wants all these to return int */
00112 # ifndef MICRO
00113 E void FDECL(exit, (int));
00114 # endif /* MICRO */
00115 /* compensate for some CSet/2 bogosities */
00116 # if defined(OS2_CSET2) && defined(OS2_CSET2_VER_2)
00117 #  define open    _open
00118 #  define close   _close
00119 #  define read    _read
00120 #  define write   _write
00121 #  define lseek   _lseek
00122 #  define chdir   _chdir
00123 #  define getcwd  _getcwd
00124 #  define setmode _setmode
00125 # endif /* OS2_CSET2 && OS2_CSET2_VER_2 */
00126 /* If flex thinks that we're not __STDC__ it declares free() to return
00127    int and we die.  We must use __STDC__ instead of NHSTDC because
00128    the former is naturally what flex tests for. */
00129 # if defined(__STDC__) || !defined(FLEX_SCANNER)
00130 #  ifndef OS2_CSET2
00131 #   ifndef MONITOR_HEAP
00132 E void FDECL(free, (genericptr_t));
00133 #   endif
00134 #  endif
00135 # endif
00136 #if !defined(__SASC_60) && !defined(_DCC) && !defined(__SC__)
00137 # if defined(AMIGA) && !defined(AZTEC_50) && !defined(__GNUC__)
00138 E int FDECL(perror, (const char *));
00139 # else
00140 #  if !(defined(ULTRIX_PROTO) && defined(__GNUC__))
00141 E void FDECL(perror, (const char *));
00142 #  endif
00143 # endif
00144 #endif
00145 #endif
00146 #endif /* LEGACY_CODE */
00147 #ifndef NeXT
00148 #ifdef POSIX_TYPES
00149 E void FDECL(qsort, (genericptr_t,size_t,size_t,
00150                      int(*)(const genericptr,const genericptr)));
00151 #else
00152 # if defined(BSD) || defined(ULTRIX)
00153 E  int qsort();
00154 # else
00155 #  if !defined(LATTICE) && !defined(AZTEC_50)
00156 E   void FDECL(qsort, (genericptr_t,size_t,size_t,
00157                        int(*)(const genericptr,const genericptr)));
00158 #  endif
00159 # endif
00160 #endif
00161 #endif /* NeXT */
00162 
00163 #ifndef __SASC_60
00164 #if !defined(AZTEC_50) && !defined(__GNUC__)
00165 /* may already be defined */
00166 
00167 # ifdef ULTRIX
00168 #  ifdef ULTRIX_PROTO
00169 E int FDECL(lseek, (int,off_t,int));
00170 #  else
00171 E long FDECL(lseek, (int,off_t,int));
00172 #  endif
00173   /* Ultrix 3.0 man page mistakenly says it returns an int. */
00174 E int FDECL(write, (int,char *,int));
00175 E int FDECL(link, (const char *, const char*));
00176 # else
00177 # ifndef bsdi
00178 E long FDECL(lseek, (int,long,int));
00179 # endif
00180 #  if defined(POSIX_TYPES) || defined(__TURBOC__)
00181 #   ifndef bsdi
00182 E int FDECL(write, (int, const void *,unsigned));
00183 #   endif
00184 #  else
00185 #   ifndef __MWERKS__   /* metrowerks defines write via universal headers */
00186 E int FDECL(write, (int,genericptr_t,unsigned));
00187 #   endif
00188 #  endif
00189 # endif /* ULTRIX */
00190 
00191 # ifdef OS2_CSET2       /* IBM CSet/2 */
00192 #  ifdef OS2_CSET2_VER_1
00193 E int FDECL(unlink, (char *));
00194 #  else
00195 E int FDECL(unlink, (const char *)); /* prototype is ok in ver >= 2 */
00196 #  endif
00197 # else
00198 #  ifndef __SC__
00199 E int FDECL(unlink, (const char *));
00200 #  endif
00201 # endif
00202 
00203 #endif /* AZTEC_50 && __GNUC__ */
00204 
00205 #ifdef MAC
00206 #ifndef __CONDITIONALMACROS__   /* universal headers */
00207 E int FDECL(close, (int));              /* unistd.h */
00208 E int FDECL(read, (int, char *, int));  /* unistd.h */
00209 E int FDECL(chdir, (const char *));     /* unistd.h */
00210 E char *FDECL(getcwd, (char *,int));    /* unistd.h */
00211 #endif
00212 
00213 E int FDECL(open, (const char *,int));
00214 #endif
00215 
00216 #if defined(MICRO)
00217 E int FDECL(close, (int));
00218 #ifndef __EMX__
00219 E int FDECL(read, (int,genericptr_t,unsigned int));
00220 #endif
00221 E int FDECL(open, (const char *,int,...));
00222 E int FDECL(dup2, (int, int));
00223 E int FDECL(setmode, (int,int));
00224 E int NDECL(kbhit);
00225 # if !defined(_DCC)
00226 #  if defined(__TURBOC__)
00227 E int FDECL(chdir, (const char *));
00228 #  else
00229 #   ifndef __EMX__
00230 E int FDECL(chdir, (char *));
00231 #   endif
00232 #  endif
00233 #  ifndef __EMX__
00234 E char *FDECL(getcwd, (char *,int));
00235 #  endif
00236 # endif /* !_DCC */
00237 #endif
00238 
00239 #ifdef ULTRIX
00240 E int FDECL(close, (int));
00241 E int FDECL(atoi, (const char *));
00242 E int FDECL(chdir, (const char *));
00243 # if !defined(ULTRIX_CC20) && !defined(__GNUC__)
00244 E int FDECL(chmod, (const char *,int));
00245 E mode_t FDECL(umask, (int));
00246 # endif
00247 E int FDECL(read, (int,genericptr_t,unsigned));
00248 /* these aren't quite right, but this saves including lots of system files */
00249 E int FDECL(stty, (int,genericptr_t));
00250 E int FDECL(gtty, (int,genericptr_t));
00251 E int FDECL(ioctl, (int, int, char*));
00252 E int FDECL(isatty, (int));     /* 1==yes, 0==no, -1==error */
00253 #include <sys/file.h>
00254 # if defined(ULTRIX_PROTO) || defined(__GNUC__)
00255 E int NDECL(fork);
00256 # else
00257 E long NDECL(fork);
00258 # endif
00259 #endif /* ULTRIX */
00260 
00261 #ifdef VMS
00262 # ifndef abs
00263 E int FDECL(abs, (int));
00264 # endif
00265 E int FDECL(atexit, (void (*)(void)));
00266 E int FDECL(atoi, (const char *));
00267 E int FDECL(chdir, (const char *));
00268 E int FDECL(chown, (const char *,unsigned,unsigned));
00269 # ifdef __DECC_VER
00270 E int FDECL(chmod, (const char *,mode_t));
00271 E mode_t FDECL(umask, (mode_t));
00272 # else
00273 E int FDECL(chmod, (const char *,int));
00274 E int FDECL(umask, (int));
00275 # endif
00276 /* #include <unixio.h> */
00277 E int FDECL(close, (int));
00278 E int VDECL(creat, (const char *,unsigned,...));
00279 E int FDECL(delete, (const char *));
00280 E int FDECL(fstat, ( /*_ int, stat_t * _*/ ));
00281 E int FDECL(isatty, (int));     /* 1==yes, 0==no, -1==error */
00282 E long FDECL(lseek, (int,long,int));
00283 E int VDECL(open, (const char *,int,unsigned,...));
00284 E int FDECL(read, (int,genericptr_t,unsigned));
00285 E int FDECL(rename, (const char *,const char *));
00286 E int FDECL(stat, ( /*_ const char *,stat_t * _*/ ));
00287 E int FDECL(write, (int,const genericptr,unsigned));
00288 #endif
00289 
00290 #endif  /* __SASC_60 */
00291 
00292 /* both old & new versions of Ultrix want these, but real BSD does not */
00293 #ifdef ultrix
00294 E void abort();
00295 E void bcopy();
00296 # ifdef ULTRIX
00297 E int FDECL(system, (const char *));
00298 #  ifndef _UNISTD_H_
00299 E int FDECL(execl, (const char *, ...));
00300 #  endif
00301 # endif
00302 #endif
00303 #ifdef MICRO
00304 E void NDECL(abort);
00305 E void FDECL(_exit, (int));
00306 E int FDECL(system, (const char *));
00307 #endif
00308 #if defined(HPUX) && !defined(_POSIX_SOURCE)
00309 E long NDECL(fork);
00310 #endif
00311 
00312 #ifdef POSIX_TYPES
00313 /* The POSIX string.h is required to define all the mem* and str* functions */
00314 #include <string.h>
00315 #else
00316 #if defined(SYSV) || defined(VMS) || defined(MAC) || defined(SUNOS4)
00317 # if defined(NHSTDC) || (defined(VMS) && !defined(ANCIENT_VAXC))
00318 #  if !defined(_AIX32) && !(defined(SUNOS4) && defined(__STDC__))
00319                                 /* Solaris unbundled cc (acc) */
00320 E int FDECL(memcmp, (const void *,const void *,size_t));
00321 E void *FDECL(memcpy, (void *, const void *, size_t));
00322 E void *FDECL(memset, (void *, int, size_t));
00323 #  endif
00324 # else
00325 #  ifndef memcmp        /* some systems seem to macro these back to b*() */
00326 E int memcmp();
00327 #  endif
00328 #  ifndef memcpy
00329 E char *memcpy();
00330 #  endif
00331 #  ifndef memset
00332 E char *memset();
00333 #  endif
00334 # endif
00335 #else
00336 # ifdef HPUX
00337 E int FDECL(memcmp, (char *,char *,int));
00338 E void *FDECL(memcpy, (char *,char *,int));
00339 E void *FDECL(memset, (char*,int,int));
00340 # endif
00341 #endif
00342 #endif /* POSIX_TYPES */
00343 
00344 #if defined(MICRO) && !defined(LATTICE)
00345 # if defined(TOS) && defined(__GNUC__)
00346 E int FDECL(memcmp, (const void *,const void *,size_t));
00347 E void *FDECL(memcpy, (void *,const void *,size_t));
00348 E void *FDECL(memset, (void *,int,size_t));
00349 # else
00350 #  if defined(AZTEC_50) || defined(NHSTDC) || defined(WIN32)
00351 E int  FDECL(memcmp, (const void *, const void *, size_t));
00352 E void *FDECL(memcpy, (void *, const void *, size_t));
00353 E void *FDECL(memset, (void *, int, size_t));
00354 #  else
00355 E int FDECL(memcmp, (char *,char *,unsigned int));
00356 E char *FDECL(memcpy, (char *,char *,unsigned int));
00357 E char *FDECL(memset, (char*,int,int));
00358 #  endif /* AZTEC_50 || NHSTDC */
00359 # endif /* TOS */
00360 #endif /* MICRO */
00361 
00362 #if defined(BSD) && defined(ultrix)     /* i.e., old versions of Ultrix */
00363 E void sleep();
00364 #endif
00365 #if defined(ULTRIX) || defined(SYSV)
00366 E unsigned sleep();
00367 #endif
00368 #if defined(HPUX)
00369 E unsigned int FDECL(sleep, (unsigned int));
00370 #endif
00371 #ifdef VMS
00372 E int FDECL(sleep, (unsigned));
00373 #endif
00374 
00375 E char *FDECL(getenv, (const char *));
00376 E char *getlogin();
00377 #if defined(HPUX) && !defined(_POSIX_SOURCE)
00378 E long NDECL(getuid);
00379 E long NDECL(getgid);
00380 E long NDECL(getpid);
00381 #else
00382 # ifdef POSIX_TYPES
00383 E pid_t NDECL(getpid);
00384 E uid_t NDECL(getuid);
00385 E gid_t NDECL(getgid);
00386 #  ifdef VMS
00387 E pid_t NDECL(getppid);
00388 #  endif
00389 # else  
00390 #  ifndef getpid                /* Borland C defines getpid() as a macro */
00391 E int NDECL(getpid);
00392 #  endif
00393 #  ifdef VMS
00394 E int NDECL(getppid);
00395 E unsigned NDECL(getuid);
00396 E unsigned NDECL(getgid);
00397 #  endif
00398 #  if defined(ULTRIX) && !defined(_UNISTD_H_)
00399 E unsigned NDECL(getuid);
00400 E unsigned NDECL(getgid);
00401 E int FDECL(setgid, (int));
00402 E int FDECL(setuid, (int));
00403 #  endif
00404 # endif /*?POSIX_TYPES*/
00405 #endif  /*?(HPUX && !_POSIX_SOURCE)*/
00406 
00407 /* add more architectures as needed */
00408 #if defined(HPUX)
00409 #define seteuid(x) setreuid(-1, (x));
00410 #endif
00411 
00412 /*# string(s).h #*/
00413 #if !defined(_XtIntrinsic_h) && !defined(POSIX_TYPES)
00414 /* <X11/Intrinsic.h> #includes <string[s].h>; so does defining POSIX_TYPES */
00415 
00416 #if (defined(ULTRIX) || defined(NeXT)) && defined(__GNUC__)
00417 #include <strings.h>
00418 #else
00419 E char  *FDECL(strcpy, (char *,const char *));
00420 E char  *FDECL(strncpy, (char *,const char *,size_t));
00421 E char  *FDECL(strcat, (char *,const char *));
00422 E char  *FDECL(strncat, (char *,const char *,size_t));
00423 E char  *FDECL(strpbrk, (const char *,const char *));
00424 
00425 # if defined(SYSV) || defined(MICRO) || defined(MAC) || defined(VMS) || defined(HPUX)
00426 E char  *FDECL(strchr, (const char *,int));
00427 E char  *FDECL(strrchr, (const char *,int));
00428 # else /* BSD */
00429 E char  *FDECL(index, (const char *,int));
00430 E char  *FDECL(rindex, (const char *,int));
00431 # endif
00432 
00433 E int   FDECL(strcmp, (const char *,const char *));
00434 E int   FDECL(strncmp, (const char *,const char *,size_t));
00435 # if defined(MICRO) || defined(MAC) || defined(VMS)
00436 E size_t FDECL(strlen, (const char *));
00437 # else
00438 # ifdef HPUX
00439 E unsigned int  FDECL(strlen, (char *));
00440 #  else
00441 #   if !(defined(ULTRIX_PROTO) && defined(__GNUC__))
00442 E int   FDECL(strlen, (const char *));
00443 #   endif
00444 #  endif /* HPUX */
00445 # endif /* MICRO */
00446 #endif /* ULTRIX */
00447 
00448 #endif  /* !_XtIntrinsic_h_ && !POSIX_TYPES */
00449 
00450 #if defined(ULTRIX) && defined(__GNUC__)
00451 E char  *FDECL(index, (const char *,int));
00452 E char  *FDECL(rindex, (const char *,int));
00453 #endif
00454 
00455 /* Old varieties of BSD have char *sprintf().
00456  * Newer varieties of BSD have int sprintf() but allow for the old char *.
00457  * Several varieties of SYSV and PC systems also have int sprintf().
00458  * If your system doesn't agree with this breakdown, you may want to change
00459  * this declaration, especially if your machine treats the types differently.
00460  * If your system defines sprintf, et al, in stdio.h, add to the initial
00461  * #if.
00462  */
00463 #if defined(ULTRIX) || defined(__DECC) || defined(__SASC_60) || defined(WIN32)
00464 #define SPRINTF_PROTO
00465 #endif
00466 #if (defined(SUNOS4) && defined(__STDC__)) || defined(_AIX32)
00467 #define SPRINTF_PROTO
00468 #endif
00469 #if defined(TOS) || defined(AZTEC_50) || defined(__sgi) || defined(__GNUC__)
00470         /* problem with prototype mismatches */
00471 #define SPRINTF_PROTO
00472 #endif
00473 #if defined(__MWERKS__) || defined(__SC__)
00474         /* Metrowerks already has a prototype for sprintf() */
00475 # define SPRINTF_PROTO
00476 #endif
00477 
00478 #ifndef SPRINTF_PROTO
00479 # if defined(POSIX_TYPES) || defined(DGUX) || defined(NeXT) || !defined(BSD)
00480 E  int FDECL(sprintf, (char *,const char *,...));
00481 # else
00482 #  define OLD_SPRINTF
00483 E  char *sprintf();
00484 # endif
00485 #endif
00486 #ifdef SPRINTF_PROTO
00487 # undef SPRINTF_PROTO
00488 #endif
00489 
00490 #ifndef __SASC_60
00491 #ifdef NEED_VARARGS
00492 # if defined(USE_STDARG) || defined(USE_VARARGS)
00493 #  if !defined(SVR4) && !defined(apollo)
00494 #   if !(defined(ULTRIX_PROTO) && defined(__GNUC__))
00495 #    if !(defined(SUNOS4) && defined(__STDC__)) /* Solaris unbundled cc (acc) */
00496 E int FDECL(vsprintf, (char *, const char *, va_list));
00497 E int FDECL(vfprintf, (FILE *, const char *, va_list));
00498 E int FDECL(vprintf, (const char *, va_list));
00499 #    endif
00500 #   endif
00501 #  endif
00502 # else
00503 #  define vprintf       printf
00504 #  define vfprintf      fprintf
00505 #  define vsprintf      sprintf
00506 # endif
00507 #endif /* NEED_VARARGS */
00508 #endif
00509 
00510 
00511 #ifdef MICRO
00512 E int FDECL(tgetent, (const char *,const char *));
00513 E void FDECL(tputs, (const char *,int,int (*)()));
00514 E int FDECL(tgetnum, (const char *));
00515 E int FDECL(tgetflag, (const char *));
00516 E char *FDECL(tgetstr, (const char *,char **));
00517 E char *FDECL(tgoto, (const char *,int,int));
00518 #else
00519 # if ! (defined(HPUX) && defined(_POSIX_SOURCE))
00520 E int FDECL(tgetent, (char *,const char *));
00521 E void FDECL(tputs, (const char *,int,int (*)()));
00522 # endif
00523 E int FDECL(tgetnum, (const char *));
00524 E int FDECL(tgetflag, (const char *));
00525 E char *FDECL(tgetstr, (const char *,char **));
00526 E char *FDECL(tgoto, (const char *,int,int));
00527 #endif
00528 
00529 #ifdef ALLOC_C
00530 E genericptr_t FDECL(malloc, (size_t));
00531 #endif
00532 
00533 /* time functions */
00534 
00535 #ifdef LEGACY_CODE
00536 # ifndef LATTICE
00537 #  if !(defined(ULTRIX_PROTO) && defined(__GNUC__))
00538 E struct tm *FDECL(localtime, (const time_t *));
00539 #  endif
00540 # endif
00541 
00542 # if defined(ULTRIX) || (defined(BSD) && defined(POSIX_TYPES)) || defined(SYSV) || defined(MICRO) || defined(VMS) || defined(MAC) || (defined(HPUX) && defined(_POSIX_SOURCE))
00543 E time_t FDECL(time, (time_t *));
00544 # else
00545 E long FDECL(time, (time_t *));
00546 # endif /* ULTRIX */
00547 #endif /* LEGACY_CODE */
00548 
00549 #ifdef VMS
00550         /* used in makedefs.c, but missing from gcc-vms's <time.h> */
00551 E char *FDECL(ctime, (const time_t *));
00552 #endif
00553 
00554 
00555 #ifdef MICRO
00556 # ifdef abs
00557 # undef abs
00558 # endif
00559 E int FDECL(abs, (int));
00560 # ifdef atoi
00561 # undef atoi
00562 # endif
00563 E int FDECL(atoi, (const char *));
00564 #endif
00565 
00566 #undef E
00567 
00568 #endif /*  !__cplusplus && !__GO32__ */
00569 
00570 #endif /* SYSTEM_H */